Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -8,6 +8,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)
|
|
|
11 |
|
12 |
custom_css = """
|
13 |
#md {
|
@@ -21,14 +22,43 @@ custom_css = """
|
|
21 |
"""
|
22 |
|
23 |
api_key = os.getenv('groq')
|
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 = {
|
@@ -100,7 +130,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
100 |
button = gr.Button("Senden")
|
101 |
|
102 |
# Connect the button to the function
|
103 |
-
button.click(fn=
|
104 |
|
105 |
# Launch the Gradio application
|
106 |
demo.launch()
|
|
|
8 |
# Load environment variables
|
9 |
genai.configure(api_key=os.environ["geminiapikey"])
|
10 |
read_key = os.environ.get('HF_TOKEN', None)
|
11 |
+
cx="77f1602c0ff764edb"
|
12 |
|
13 |
custom_css = """
|
14 |
#md {
|
|
|
22 |
"""
|
23 |
|
24 |
api_key = os.getenv('groq')
|
25 |
+
google_api_key = os.getenv('google_search')
|
26 |
if api_key is None:
|
27 |
raise ValueError("groq_whisper environment variable is not set")
|
28 |
|
29 |
# Initialize the Groq client
|
30 |
client = Groq(api_key=api_key)
|
31 |
|
32 |
+
def perform_search(prompt):
|
33 |
+
if prompt.strip() == '':
|
34 |
+
return '' # Return empty string for empty search
|
35 |
+
|
36 |
+
# URL der Google Custom Search API
|
37 |
+
url = f"https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={cx}&q={prompt}"
|
38 |
+
|
39 |
+
try:
|
40 |
+
# HTTP GET-Anfrage an die Google Custom Search API
|
41 |
+
response = requests.get(url)
|
42 |
+
response.raise_for_status() # Wirft eine Exception, wenn die Anfrage fehlschlägt
|
43 |
+
|
44 |
+
# JSON-Antwort parsen
|
45 |
+
data = response.json()
|
46 |
+
|
47 |
+
# Extrahiere die Suchergebnisse
|
48 |
+
items = data.get('items', [])
|
49 |
+
results = [item['snippet'] for item in items]
|
50 |
+
|
51 |
+
# Kombiniere die Ergebnisse zu einem String
|
52 |
+
result_text = '\n'.join(results)
|
53 |
+
|
54 |
+
# Formuliere die Antwort
|
55 |
+
search_query = f"{prompt} antworte kurz und knapp. antworte auf deutsch. du findest die antwort hier: {result_text}"
|
56 |
+
|
57 |
+
return search_query
|
58 |
|
59 |
+
except requests.exceptions.RequestException as e:
|
60 |
+
print(f"An error occurred: {e}")
|
61 |
+
return ''
|
62 |
|
63 |
def predict(prompt):
|
64 |
generation_config = {
|
|
|
130 |
button = gr.Button("Senden")
|
131 |
|
132 |
# Connect the button to the function
|
133 |
+
button.click(fn=perform_search, inputs=ort_input, outputs=details_output)
|
134 |
|
135 |
# Launch the Gradio application
|
136 |
demo.launch()
|