Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -71,42 +71,64 @@ def load_chat(name):
|
|
71 |
return [], [], f"β Load error: {e}"
|
72 |
|
73 |
with gr.Blocks(css="""
|
74 |
-
body { background-color: #111
|
75 |
-
.gr-chatbot { border
|
76 |
-
.gr-chatbot-message { background-color: #292929
|
77 |
-
textarea, input[type='text'] {
|
78 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
.gr-button:hover { background-color: #555 !important; cursor: pointer; }
|
80 |
-
.gr-dropdown { background-color: #222
|
81 |
-
h1, h2, h3, .gr-markdown { color: #f1f1f1
|
82 |
-
|
|
|
83 |
""") as demo:
|
84 |
|
85 |
state = gr.State([])
|
|
|
86 |
|
87 |
gr.Markdown("# β¨ JAWERIA'SBOT π€")
|
88 |
gr.Markdown("Speak or type β your assistant listens and replies with text and emojis π¬")
|
89 |
|
90 |
chatbot = gr.Chatbot(type="messages", height=400)
|
91 |
-
chat_input = gr.Textbox(label="π¬ Message", placeholder="Type or speak your message...")
|
92 |
-
send_btn = gr.Button("Send π")
|
93 |
|
94 |
with gr.Row():
|
95 |
-
|
96 |
-
|
|
|
|
|
97 |
|
98 |
with gr.Row():
|
99 |
new_chat_btn = gr.Button("π New")
|
100 |
save_btn = gr.Button("πΎ Save")
|
101 |
-
saved_dropdown = gr.Dropdown(label="π Load Saved", choices=list_saved_files())
|
102 |
load_btn = gr.Button("π₯ Load")
|
103 |
|
104 |
save_msg = gr.Markdown()
|
105 |
load_msg = gr.Markdown()
|
106 |
|
|
|
107 |
send_btn.click(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
|
108 |
chat_input.submit(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
new_chat_btn.click(fn=lambda: ("", [], []), outputs=[chat_input, chatbot, state])
|
111 |
save_btn.click(fn=save_session, inputs=[state], outputs=[save_msg])
|
112 |
save_btn.click(fn=list_saved_files, outputs=[saved_dropdown])
|
|
|
71 |
return [], [], f"β Load error: {e}"
|
72 |
|
73 |
with gr.Blocks(css="""
|
74 |
+
body { background-color: #111; font-family: 'Segoe UI', sans-serif; }
|
75 |
+
.gr-chatbot { border: 1px solid #333; background-color: #1e1e1e; border-radius: 10px; }
|
76 |
+
.gr-chatbot-message { background-color: #292929; color: #f1f1f1; border-radius: 10px; margin-bottom: 5px; }
|
77 |
+
textarea, input[type='text'] {
|
78 |
+
background-color: #222; color: #fff; border-radius: 30px !important;
|
79 |
+
border: 1px solid #444; padding: 10px 50px 10px 15px; height: 48px;
|
80 |
+
}
|
81 |
+
.gr-button {
|
82 |
+
background-color: #333 !important; color: #fff !important;
|
83 |
+
border: 1px solid #444 !important; border-radius: 8px;
|
84 |
+
font-weight: bold; transition: background-color 0.2s;
|
85 |
+
}
|
86 |
.gr-button:hover { background-color: #555 !important; cursor: pointer; }
|
87 |
+
.gr-dropdown { background-color: #222; color: #fff; max-height: 200px; overflow-y: auto; }
|
88 |
+
h1, h2, h3, .gr-markdown { color: #f1f1f1; text-align: center; }
|
89 |
+
input[type="file"] { color: white; }
|
90 |
+
#mic-dropdown { position: absolute; right: 20px; top: 8px; }
|
91 |
""") as demo:
|
92 |
|
93 |
state = gr.State([])
|
94 |
+
audio_file = gr.File(visible=False)
|
95 |
|
96 |
gr.Markdown("# β¨ JAWERIA'SBOT π€")
|
97 |
gr.Markdown("Speak or type β your assistant listens and replies with text and emojis π¬")
|
98 |
|
99 |
chatbot = gr.Chatbot(type="messages", height=400)
|
|
|
|
|
100 |
|
101 |
with gr.Row():
|
102 |
+
chat_input = gr.Textbox(label="π¬", placeholder="Type your message...", scale=9)
|
103 |
+
mic_menu = gr.Dropdown(choices=["ποΈ Record Audio", "π Upload File"], label="", value=None, scale=1, interactive=True)
|
104 |
+
|
105 |
+
send_btn = gr.Button("Send π")
|
106 |
|
107 |
with gr.Row():
|
108 |
new_chat_btn = gr.Button("π New")
|
109 |
save_btn = gr.Button("πΎ Save")
|
110 |
+
saved_dropdown = gr.Dropdown(label="π Load Saved", choices=list_saved_files(), interactive=True)
|
111 |
load_btn = gr.Button("π₯ Load")
|
112 |
|
113 |
save_msg = gr.Markdown()
|
114 |
load_msg = gr.Markdown()
|
115 |
|
116 |
+
# Event handlers
|
117 |
send_btn.click(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
|
118 |
chat_input.submit(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
|
119 |
+
|
120 |
+
def handle_mic_choice(choice):
|
121 |
+
if choice == "ποΈ Record Audio":
|
122 |
+
return gr.Audio(source="microphone", type="filepath", label="Recording... ποΈ", interactive=True, visible=True)
|
123 |
+
elif choice == "π Upload File":
|
124 |
+
return gr.Audio(source="upload", type="filepath", label="Upload Audio π", interactive=True, visible=True)
|
125 |
+
else:
|
126 |
+
return gr.update(visible=False)
|
127 |
+
|
128 |
+
mic_audio = gr.Audio(visible=False, type="filepath")
|
129 |
+
mic_menu.change(handle_mic_choice, inputs=mic_menu, outputs=mic_audio)
|
130 |
+
mic_audio.change(transcribe_audio, inputs=mic_audio, outputs=chat_input)
|
131 |
+
|
132 |
new_chat_btn.click(fn=lambda: ("", [], []), outputs=[chat_input, chatbot, state])
|
133 |
save_btn.click(fn=save_session, inputs=[state], outputs=[save_msg])
|
134 |
save_btn.click(fn=list_saved_files, outputs=[saved_dropdown])
|