JaweriaGenAI commited on
Commit
299800e
Β·
verified Β·
1 Parent(s): 910270b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -13
app.py CHANGED
@@ -5,13 +5,13 @@ from pydub import AudioSegment
5
  import whisper
6
  import requests
7
 
8
- # πŸ” API key
9
- groq_key = "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" # Replace with your actual Groq key
10
 
11
- # 🧠 Load Whisper locally
12
- whisper_model = whisper.load_model("base") # Use "small"/"medium"/"large" for better results
13
 
14
- # πŸ’¬ Chat using Groq
15
  def chat_with_groq(message, history):
16
  messages = [{"role": "system", "content": "You are JAWERIA'SBOT πŸ€– – cheerful, emoji-savvy, and sleek."}]
17
  messages += history + [{"role": "user", "content": message}]
@@ -32,7 +32,7 @@ def chat_with_groq(message, history):
32
  history += [{"role": "user", "content": message}, {"role": "assistant", "content": reply}]
33
  return "", history, history
34
 
35
- # πŸŽ™οΈ Transcribe voice to text
36
  def transcribe_audio(audio_path):
37
  if audio_path is None or not os.path.exists(audio_path):
38
  return "⚠️ No audio recorded."
@@ -68,17 +68,39 @@ def load_chat(name):
68
  except Exception as e:
69
  return [], [], f"❌ Load error: {e}"
70
 
71
- # πŸŒ™ Gradio UI
72
  with gr.Blocks(css="""
73
- body {background-color: #111 !important; color: white;}
74
- .gr-chatbot-message {background-color: #222 !important; color: white !important; border-radius: 6px;}
75
- input[type='text'], textarea, select, .gr-textbox {background-color: #222 !important; color: white !important;}
76
- .gr-button {background-color: #007acc !important; color: white !important;}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  """) as demo:
78
 
79
  state = gr.State([])
80
 
81
- gr.Markdown("<h1 style='text-align:center; color:#00ccff;'>✨ JAWERIA'SBOT πŸ€–</h1>")
82
  gr.Markdown("<div style='text-align:center;'>Speak or type β€” your assistant listens and replies with text πŸ’¬</div>")
83
 
84
  chatbot = gr.Chatbot(type="messages", height=350)
@@ -98,7 +120,7 @@ input[type='text'], textarea, select, .gr-textbox {background-color: #222 !impor
98
  save_msg = gr.Markdown()
99
  load_msg = gr.Markdown()
100
 
101
- # πŸ”— Bind actions
102
  send_btn.click(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
103
  chat_input.submit(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
104
  voice_btn.click(transcribe_audio, inputs=[voice_input], outputs=[chat_input])
 
5
  import whisper
6
  import requests
7
 
8
+ # πŸ” Load API key securely from environment
9
+ groq_key = os.getenv("GROQ_API_KEY")
10
 
11
+ # 🧠 Load Whisper model
12
+ whisper_model = whisper.load_model("base")
13
 
14
+ # πŸ’¬ Chat function
15
  def chat_with_groq(message, history):
16
  messages = [{"role": "system", "content": "You are JAWERIA'SBOT πŸ€– – cheerful, emoji-savvy, and sleek."}]
17
  messages += history + [{"role": "user", "content": message}]
 
32
  history += [{"role": "user", "content": message}, {"role": "assistant", "content": reply}]
33
  return "", history, history
34
 
35
+ # πŸŽ™οΈ Audio transcription
36
  def transcribe_audio(audio_path):
37
  if audio_path is None or not os.path.exists(audio_path):
38
  return "⚠️ No audio recorded."
 
68
  except Exception as e:
69
  return [], [], f"❌ Load error: {e}"
70
 
71
+ # 🌌 Gradio UI
72
  with gr.Blocks(css="""
73
+ body {
74
+ background-color: #111 !important;
75
+ color: white !important;
76
+ }
77
+ * {
78
+ color: white !important;
79
+ }
80
+ h1 {
81
+ text-align: center !important;
82
+ color: #00ccff !important;
83
+ margin: auto !important;
84
+ }
85
+ .gr-chatbot-message, .gr-textbox, textarea, input[type='text'],
86
+ select, .gr-dropdown, .gr-markdown, .gr-label {
87
+ background-color: #222 !important;
88
+ color: white !important;
89
+ border-radius: 6px;
90
+ }
91
+ .gr-button {
92
+ background-color: #007acc !important;
93
+ color: white !important;
94
+ }
95
+ .gr-dropdown {
96
+ max-height: 150px;
97
+ overflow-y: auto;
98
+ }
99
  """) as demo:
100
 
101
  state = gr.State([])
102
 
103
+ gr.Markdown("# ✨ JAWERIA'SBOT πŸ€–")
104
  gr.Markdown("<div style='text-align:center;'>Speak or type β€” your assistant listens and replies with text πŸ’¬</div>")
105
 
106
  chatbot = gr.Chatbot(type="messages", height=350)
 
120
  save_msg = gr.Markdown()
121
  load_msg = gr.Markdown()
122
 
123
+ # πŸ”— Bind events
124
  send_btn.click(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
125
  chat_input.submit(chat_with_groq, inputs=[chat_input, state], outputs=[chat_input, chatbot, state])
126
  voice_btn.click(transcribe_audio, inputs=[voice_input], outputs=[chat_input])