Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -23,67 +23,25 @@ custom_css = """
|
|
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 |
#very simple (and extremly fast) websearch
|
33 |
def websearch(prompt):
|
34 |
headers = {
|
35 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
36 |
}
|
37 |
-
url = f"https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={cx}&q={prompt}"
|
38 |
-
|
39 |
response = requests.get(url, headers=headers)
|
40 |
data = response.json() # JSON-Daten direkt verarbeiten
|
41 |
# Extrahieren des Textes aus den Ergebnissen
|
42 |
items = data.get('items', [])
|
43 |
results = [item['snippet'] for item in items]
|
44 |
-
result_text = '\n'.join(results)
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
52 |
-
response_text = soup.find('body')
|
53 |
-
#prompt = f"{search_term}\n use this result from a google search to answer the question \n {response_text.text}"
|
54 |
-
#result = predict(prompt)
|
55 |
-
return response_text.text
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
def perform_search(prompt):
|
60 |
-
if prompt.strip() == '':
|
61 |
-
return '' # Return empty string for empty search
|
62 |
-
|
63 |
-
# URL der Google Custom Search API
|
64 |
-
url = f"https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={cx}&q={prompt}"
|
65 |
-
|
66 |
-
try:
|
67 |
-
# HTTP GET-Anfrage an die Google Custom Search API
|
68 |
-
response = requests.get(url)
|
69 |
-
# JSON-Antwort parsen
|
70 |
-
data = response.json()
|
71 |
-
# Extrahiere die Suchergebnisse
|
72 |
-
items = data.get('items', [])
|
73 |
-
results = [item['snippet'] for item in items]
|
74 |
-
#return results[0]
|
75 |
-
# Kombiniere die Ergebnisse zu einem String
|
76 |
-
result_text = '\n'.join(results)
|
77 |
-
#return results[0]
|
78 |
-
# Formuliere die Antwort
|
79 |
-
#search_query = f"{prompt} antworte kurz und knapp. antworte auf deutsch. du findest die antwort hier: {result_text}"
|
80 |
-
#result = predict(search_query)
|
81 |
-
#return result
|
82 |
-
return result_text
|
83 |
-
|
84 |
-
except requests.exceptions.RequestException as e:
|
85 |
-
print(f"An error occurred: {e}")
|
86 |
-
return ''
|
87 |
|
88 |
def predict(prompt):
|
89 |
generation_config = {
|
|
|
23 |
|
24 |
#api_key = os.getenv('groq')
|
25 |
google_api_key = os.getenv('google_search')
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
#very simple (and extremly fast) websearch
|
28 |
def websearch(prompt):
|
29 |
headers = {
|
30 |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
31 |
}
|
32 |
+
url = f"https://www.googleapis.com/customsearch/v1?key={google_api_key}&cx={cx}&q={prompt}"
|
|
|
33 |
response = requests.get(url, headers=headers)
|
34 |
data = response.json() # JSON-Daten direkt verarbeiten
|
35 |
# Extrahieren des Textes aus den Ergebnissen
|
36 |
items = data.get('items', [])
|
37 |
results = [item['snippet'] for item in items]
|
38 |
+
result_text = '\n'.join(results)
|
39 |
+
# Formuliere die Antwort
|
40 |
+
search_query = f"{prompt} antworte kurz und knapp. antworte auf deutsch. du findest die antwort hier: {result_text}"
|
41 |
+
result = predict(search_query)
|
42 |
+
return result
|
43 |
+
#return results[0]
|
44 |
+
#return result_text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
def predict(prompt):
|
47 |
generation_config = {
|