JaweriaGenAI commited on
Commit
d0bfe9a
Β·
verified Β·
1 Parent(s): bc8848c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -14
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 !important; font-family: 'Segoe UI', sans-serif !important; }
75
- .gr-chatbot { border-radius: 10px; border: 1px solid #333; background-color: #1e1e1e !important; }
76
- .gr-chatbot-message { background-color: #292929 !important; color: #f1f1f1 !important; border-radius: 10px; margin-bottom: 5px; }
77
- textarea, input[type='text'] { background-color: #222 !important; color: #fff !important; border-radius: 8px !important; border: 1px solid #444 !important; padding: 10px; }
78
- .gr-button { background-color: #333 !important; color: #fff !important; border: 1px solid #444 !important; border-radius: 8px; padding: 8px 14px; font-weight: bold; transition: background-color 0.2s; }
 
 
 
 
 
 
 
79
  .gr-button:hover { background-color: #555 !important; cursor: pointer; }
80
- .gr-dropdown { background-color: #222 !important; color: #fff !important; border-radius: 8px; border: 1px solid #444; padding: 8px; }
81
- h1, h2, h3, .gr-markdown { color: #f1f1f1 !important; text-align: center; }
82
- audio { background-color: #000 !important; border: 1px solid #333 !important; }
 
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
- voice_input = gr.Audio(label="🎀 Speak", type="filepath", interactive=True)
96
- voice_btn = gr.Button("πŸŽ™οΈ Transcribe to Text")
 
 
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
- voice_btn.click(transcribe_audio, inputs=[voice_input], outputs=[chat_input])
 
 
 
 
 
 
 
 
 
 
 
 
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])