mgokg commited on
Commit
0a61873
·
verified ·
1 Parent(s): 7405511

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -2
app.py CHANGED
@@ -4,7 +4,7 @@ import os
4
  import json
5
  import google.generativeai as genai
6
  from bs4 import BeautifulSoup
7
-
8
  # Load environment variables
9
  genai.configure(api_key=os.environ["geminiapikey"])
10
  read_key = os.environ.get('HF_TOKEN', None)
@@ -20,6 +20,16 @@ custom_css = """
20
  }
21
  """
22
 
 
 
 
 
 
 
 
 
 
 
23
  def predict(prompt):
24
  generation_config = {
25
  "temperature": 0.4,
@@ -54,7 +64,43 @@ def websearch(search_term):
54
  prompt = f"{search_term}\n use this result from a google search to answer the question \n {response_text.text}"
55
  result = predict(prompt)
56
  return result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
 
 
58
  # Create the Gradio interface
59
  with gr.Blocks(css=custom_css) as demo:
60
  with gr.Row():
@@ -69,4 +115,7 @@ with gr.Blocks(css=custom_css) as demo:
69
  button.click(fn=websearch, inputs=ort_input, outputs=details_output)
70
 
71
  # Launch the Gradio application
72
- demo.launch()
 
 
 
 
4
  import json
5
  import google.generativeai as genai
6
  from bs4 import BeautifulSoup
7
+ from groq import Groq
8
  # Load environment variables
9
  genai.configure(api_key=os.environ["geminiapikey"])
10
  read_key = os.environ.get('HF_TOKEN', None)
 
20
  }
21
  """
22
 
23
+ api_key = os.getenv('groq_whisper')
24
+
25
+ if api_key is None:
26
+ raise ValueError("groq_whisper environment variable is not set")
27
+
28
+ # Initialize the Groq client
29
+ client = Groq(api_key=api_key)
30
+
31
+
32
+
33
  def predict(prompt):
34
  generation_config = {
35
  "temperature": 0.4,
 
64
  prompt = f"{search_term}\n use this result from a google search to answer the question \n {response_text.text}"
65
  result = predict(prompt)
66
  return result
67
+
68
+
69
+ def process_audio(file_path):
70
+ try:
71
+ # Open the audio file
72
+ with open(file_path, "rb") as file:
73
+ # Create a translation of the audio file
74
+ translation = client.audio.transcriptions.create(
75
+ file=(os.path.basename(file_path), file.read()), # Correct passing of filename
76
+ model="whisper-large-v3-turbo", # Required model to use for translation
77
+ prompt="transcribe", # Optional
78
+ language="de", # Optional
79
+ response_format="json", # Optional
80
+ temperature=0.0 # Optional
81
+ )
82
+ # Return the translation text
83
+ suche = websearch(translation.text)
84
+ result = predict(suche)
85
+ return result
86
+ return translation.text
87
+ except Exception as e:
88
+ return f"An error occurred: {str(e)}"
89
+
90
+
91
+ with gr.Blocks() as speech:
92
+ with gr.Row():
93
+ sr_outputs = gr.Textbox(label="Antwort")
94
+ with gr.Row():
95
+ sr_inputs = gr.Microphone(type="filepath")
96
+ sr_inputs.change(process_audio, inputs=sr_inputs, outputs=sr_outputs)
97
+
98
+ speech.launch()
99
+
100
+
101
 
102
+
103
+ """
104
  # Create the Gradio interface
105
  with gr.Blocks(css=custom_css) as demo:
106
  with gr.Row():
 
115
  button.click(fn=websearch, inputs=ort_input, outputs=details_output)
116
 
117
  # Launch the Gradio application
118
+ demo.launch()
119
+ """
120
+
121
+