Wfafa commited on
Commit
adfc96d
Β·
verified Β·
1 Parent(s): ed034ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -118
app.py CHANGED
@@ -2,135 +2,124 @@ import gradio as gr
2
  import time
3
 
4
  # ========================================
5
- # πŸ’¬ Your AI function (replace with your logic)
6
  # ========================================
7
  def ai_response(message, history):
8
- # Here you can call your real AI model or API (e.g., DeepSeek or Hugging Face)
9
- time.sleep(1) # simulate a delay
10
- return "πŸ€– AI: I received β€” " + message
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  # ========================================
14
- # πŸŒ™ Dark Themed Gradio Interface
15
  # ========================================
16
- with gr.Blocks(theme=gr.themes.Base()) as demo:
17
- gr.HTML("""
18
- <style>
19
- body {
20
- background: linear-gradient(135deg, #0d0d0d 0%, #1a1a1a 100%);
21
- color: #f0f0f0;
22
- margin: 0;
23
- font-family: 'Roboto', sans-serif;
24
- height: 100vh;
25
- overflow: hidden;
26
- }
27
- .container {
28
- display: flex;
29
- height: 100vh;
30
- }
31
- .sidebar {
32
- width: 260px;
33
- background-color: #2a2a2a;
34
- border-right: 2px solid #444;
35
- padding: 20px;
36
- display: flex;
37
- flex-direction: column;
38
- box-shadow: inset -5px 0 10px rgba(0,0,0,0.5);
39
- }
40
- .sidebar h2 {
41
- color: #03dac6;
42
- font-weight: 400;
43
- text-align: center;
44
- margin-bottom: 25px;
45
- }
46
- .sidebar button {
47
- background-color: transparent;
48
- border: none;
49
- color: #f0f0f0;
50
- text-align: left;
51
- padding: 12px;
52
- margin-bottom: 8px;
53
- border-radius: 8px;
54
- cursor: pointer;
55
- transition: 0.3s;
56
- font-size: 15px;
57
- }
58
- .sidebar button:hover {
59
- background-color: #444;
60
- transform: translateX(4px);
61
- }
62
- .main {
63
- flex: 1;
64
- display: flex;
65
- flex-direction: column;
66
- background-color: transparent;
67
- }
68
- .chatbox {
69
- flex: 1;
70
- background-color: transparent;
71
- padding: 20px;
72
- overflow-y: auto;
73
- display: flex;
74
- flex-direction: column;
75
- }
76
- .input-area {
77
- background-color: #2a2a2a;
78
- padding: 20px;
79
- border-top: 2px solid #444;
80
- display: flex;
81
- align-items: center;
82
- }
83
- input[type='text'] {
84
- flex: 1;
85
- background-color: #444;
86
- color: #f0f0f0;
87
- border: none;
88
- border-radius: 25px;
89
- padding: 12px 20px;
90
- font-size: 15px;
91
- outline: none;
92
- }
93
- button.send-btn {
94
- margin-left: 10px;
95
- background: linear-gradient(135deg, #03dac6 0%, #00bfa5 100%);
96
- border: none;
97
- color: #0d0d0d;
98
- font-weight: bold;
99
- border-radius: 25px;
100
- padding: 12px 20px;
101
- cursor: pointer;
102
- transition: 0.3s;
103
- }
104
- button.send-btn:hover {
105
- transform: scale(1.05);
106
- box-shadow: 0 0 10px rgba(3, 218, 198, 0.5);
107
- }
108
- </style>
109
- """)
110
 
111
- # Sidebar
112
- with gr.Row(elem_classes="container"):
113
- with gr.Column(elem_classes="sidebar"):
114
- gr.HTML("<h2>AI Agent</h2>")
115
- study_tutor = gr.Button("πŸ“˜ Study Tutor")
116
- study_planner = gr.Button("πŸ—“οΈ Study Planner")
117
- study_advisor = gr.Button("🧠 Study Advisor")
118
- gr.Markdown("---")
119
- gr.Markdown("✨ <small>By Cherry</small>")
 
120
 
121
  # Main Chat Section
122
- with gr.Column(elem_classes="main"):
123
- chatbot = gr.Chatbot(height=500, show_label=False, elem_classes="chatbox")
124
- msg = gr.Textbox(placeholder="Type your query here...", show_label=False)
125
- send = gr.Button("Send", elem_classes="send-btn")
126
-
127
- def respond(message, history):
128
- history = history or []
129
- reply = ai_response(message, history)
130
- history.append((message, reply))
131
- return "", history
132
 
 
133
  msg.submit(respond, [msg, chatbot], [msg, chatbot])
134
  send.click(respond, [msg, chatbot], [msg, chatbot])
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  demo.launch()
 
2
  import time
3
 
4
  # ========================================
5
+ # πŸ’¬ AI Response Function (Replace this with your real AI)
6
  # ========================================
7
  def ai_response(message, history):
8
+ # Example: Simulate AI typing delay
9
+ time.sleep(0.8)
10
+ # You can connect this to any API (e.g., DeepSeek, Hugging Face, OpenAI)
11
+ return f"πŸ€– AI: I understood your question β€” '{message}'. Let’s explore that together!"
12
+
13
+ # ========================================
14
+ # βš™οΈ Chat Logic
15
+ # ========================================
16
+ def respond(message, history):
17
+ history = history or []
18
+ bot_message = ai_response(message, history)
19
+ history.append((message, bot_message))
20
+ return "", history
21
 
22
 
23
  # ========================================
24
+ # 🎨 Gradio Interface
25
  # ========================================
26
+ with gr.Blocks(css="""
27
+ body {
28
+ background: linear-gradient(135deg, #0d0d0d 0%, #1a1a1a 100%);
29
+ color: #f0f0f0;
30
+ font-family: 'Roboto', sans-serif;
31
+ }
32
+ #chatbot {
33
+ background-color: transparent !important;
34
+ border: none !important;
35
+ }
36
+ .send-btn {
37
+ background: linear-gradient(135deg, #03dac6 0%, #00bfa5 100%) !important;
38
+ color: #0d0d0d !important;
39
+ border: none !important;
40
+ font-weight: bold;
41
+ border-radius: 25px !important;
42
+ padding: 10px 20px !important;
43
+ transition: 0.3s;
44
+ }
45
+ .send-btn:hover {
46
+ transform: scale(1.05);
47
+ box-shadow: 0 0 12px rgba(3, 218, 198, 0.6);
48
+ }
49
+ .sidebar {
50
+ background-color: #2a2a2a;
51
+ padding: 25px;
52
+ border-right: 2px solid #444;
53
+ box-shadow: inset -5px 0 10px rgba(0,0,0,0.4);
54
+ height: 100vh;
55
+ }
56
+ .sidebar h2 {
57
+ color: #03dac6;
58
+ text-align: center;
59
+ font-weight: 400;
60
+ margin-bottom: 25px;
61
+ }
62
+ .sidebar-btn {
63
+ display: block;
64
+ width: 100%;
65
+ background: transparent;
66
+ color: #f0f0f0;
67
+ border: none;
68
+ text-align: left;
69
+ padding: 12px 15px;
70
+ border-radius: 8px;
71
+ font-size: 15px;
72
+ margin-bottom: 5px;
73
+ cursor: pointer;
74
+ transition: all 0.3s ease;
75
+ }
76
+ .sidebar-btn:hover {
77
+ background-color: #444;
78
+ transform: translateX(5px);
79
+ }
80
+ .footer {
81
+ font-size: 12px;
82
+ text-align: center;
83
+ margin-top: auto;
84
+ color: #aaa;
85
+ }
86
+ """) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
+ # ========== Layout ==========
89
+ with gr.Row():
90
+ # Sidebar Section
91
+ with gr.Column(scale=1, elem_classes="sidebar"):
92
+ gr.HTML("<h2>AI Study Agent</h2>")
93
+ tutor_btn = gr.Button("πŸ“˜ Study Tutor", elem_classes="sidebar-btn")
94
+ planner_btn = gr.Button("πŸ—“οΈ Study Planner", elem_classes="sidebar-btn")
95
+ advisor_btn = gr.Button("🧠 Study Advisor", elem_classes="sidebar-btn")
96
+ gr.Markdown("<hr>")
97
+ gr.Markdown("✨ <small>Designed by Cherry</small>", elem_classes="footer")
98
 
99
  # Main Chat Section
100
+ with gr.Column(scale=4):
101
+ chatbot = gr.Chatbot(label="", elem_id="chatbot", height=550)
102
+ with gr.Row():
103
+ msg = gr.Textbox(placeholder="Type your question here...", show_label=False, scale=5)
104
+ send = gr.Button("Send", elem_classes="send-btn", scale=1)
 
 
 
 
 
105
 
106
+ # Chat connections
107
  msg.submit(respond, [msg, chatbot], [msg, chatbot])
108
  send.click(respond, [msg, chatbot], [msg, chatbot])
109
 
110
+ # Sidebar button responses
111
+ def sidebar_action(choice, history):
112
+ response = f"✨ You selected **{choice}** β€” How can I assist with that?"
113
+ history = history or []
114
+ history.append((f"{choice}", response))
115
+ return history
116
+
117
+ tutor_btn.click(sidebar_action, ["Study Tutor", chatbot], chatbot)
118
+ planner_btn.click(sidebar_action, ["Study Planner", chatbot], chatbot)
119
+ advisor_btn.click(sidebar_action, ["Study Advisor", chatbot], chatbot)
120
+
121
+
122
+ # ========================================
123
+ # πŸš€ Launch App
124
+ # ========================================
125
  demo.launch()