navjotk commited on
Commit
6512a89
·
verified ·
1 Parent(s): 90bc7cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -10
app.py CHANGED
@@ -10,6 +10,17 @@ if not GOOGLE_API_KEY:
10
  configure(api_key=GOOGLE_API_KEY)
11
  gemini_model = GenerativeModel("models/gemini-1.5-flash")
12
 
 
 
 
 
 
 
 
 
 
 
 
13
  def get_gemini_response(query):
14
  try:
15
  response = gemini_model.generate_content(f"ਪੰਜਾਬੀ ਵਿੱਚ ਜਵਾਬ ਦਿਓ: {query}")
@@ -33,16 +44,14 @@ def handle_voice_query(audio_file):
33
  return query, response, audio_path
34
 
35
  with gr.Blocks() as demo:
36
- gr.Markdown("# 🌾 **AgroVision: ਪੰਜਾਬੀ ਵੈਚਲਣ ਸਹਾਇਕ**")
37
-
38
- with gr.TabItem("🗣️ ਆਵਾਜ਼ ਰਾਹੀਂ ਪੁੱਛੋ"):
39
- gr.Markdown("### ਆਪਣਾ ਸਵਾਲ ਆਵਾਜ਼ ਰਾਹੀਂ ਪੁੱਛੋ (ਪੰਜਾਬੀ ਵਿੱਚ)")
40
- audio_input = gr.Audio(type="filepath", label="🎤 ਸਵਾਲ ਬੋਲੋ")
41
- query_text = gr.Textbox(label="🔍 ਬੋਲਿਆ ਗਿਆ ਸਵਾਲ")
42
- gemini_response = gr.Textbox(label="📜 Gemini ਜਵਾਬ")
43
- audio_output = gr.Audio(label="🔊 ਆਵਾਜ਼ੀ ਜਵਾਬ")
44
- submit_btn = gr.Button("➡️ ਜਵਾਬ ਲਵੋ")
45
- submit_btn.click(fn=handle_voice_query,
46
  inputs=[audio_input],
47
  outputs=[query_text, gemini_response, audio_output])
48
 
 
10
  configure(api_key=GOOGLE_API_KEY)
11
  gemini_model = GenerativeModel("models/gemini-1.5-flash")
12
 
13
+ def transcribe_audio(audio_path):
14
+ recognizer = sr.Recognizer()
15
+ with sr.AudioFile(audio_path) as source:
16
+ audio = recognizer.record(source)
17
+ try:
18
+ return recognizer.recognize_google(audio, language='pa-IN')
19
+ except sr.UnknownValueError:
20
+ return "❌ ਆਵਾਜ਼ ਨੂੰ ਸਮਝਿਆ ਨਹੀਂ ਜਾ ਸਕਿਆ।"
21
+ except sr.RequestError:
22
+ return "❌ ਗੂਗਲ ਸਪੀਚ ਐਪੀਆਈ ਨਾਲ ਕਨੇਕਟ ਨਹੀਂ ਹੋ ਸਕਿਆ।"
23
+
24
  def get_gemini_response(query):
25
  try:
26
  response = gemini_model.generate_content(f"ਪੰਜਾਬੀ ਵਿੱਚ ਜਵਾਬ ਦਿਓ: {query}")
 
44
  return query, response, audio_path
45
 
46
  with gr.Blocks() as demo:
47
+ gr.Markdown("# 🗣️ ** ਆਵਾਜ਼ ਰਾਹੀਂ ਪੁੱਛੋ**")
48
+ gr.Markdown("### ਆਪਣਾ ਸਵਾਲ ਆਵਾਜ਼ ਰਾਹੀਂ ਪੁੱਛੋ (ਪੰਜਾਬੀ ਵਿੱਚ)")
49
+ audio_input = gr.Audio(type="filepath", label="🎤 ਸਵਾਲ ਬੋਲੋ")
50
+ query_text = gr.Textbox(label="🔍 ਬੋਲਿਆ ਗਿਆ ਸਵਾਲ")
51
+ gemini_response = gr.Textbox(label="📜 Gemini ਜਵਾਬ")
52
+ audio_output = gr.Audio(label="🔊 ਆਵਾਜ਼ੀ ਜਵਾਬ")
53
+ submit_btn = gr.Button("➡️ ਜਵਾਬ ਲਵੋ")
54
+ submit_btn.click(fn=handle_voice_query,
 
 
55
  inputs=[audio_input],
56
  outputs=[query_text, gemini_response, audio_output])
57