Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ custom_css = """
|
|
14 |
#md {
|
15 |
height: 400px;
|
16 |
font-size: 30px;
|
17 |
-
background: #
|
18 |
padding: 20px;
|
19 |
color: white;
|
20 |
border: 1 px solid white;
|
@@ -34,17 +34,7 @@ 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 |
-
|
38 |
-
url = f"https://www.google.com/search?q={prompt}"
|
39 |
-
|
40 |
-
response = requests.get(url, headers=headers)
|
41 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
42 |
-
response_text = soup.find('body')
|
43 |
-
#prompt = f"{search_term}\n use this result from a google search to answer the question \n {response_text.text}"
|
44 |
-
#result = predict(prompt)
|
45 |
-
return response_text.text
|
46 |
-
|
47 |
-
|
48 |
|
49 |
response = requests.get(url, headers=headers)
|
50 |
data = response.json() # JSON-Daten direkt verarbeiten
|
@@ -52,7 +42,7 @@ def websearch(prompt):
|
|
52 |
items = data.get('items', [])
|
53 |
results = [item['snippet'] for item in items]
|
54 |
result_text = '\n'.join(results)
|
55 |
-
|
56 |
return result_text
|
57 |
|
58 |
# URL der Google Custom Search API
|
|
|
14 |
#md {
|
15 |
height: 400px;
|
16 |
font-size: 30px;
|
17 |
+
background: #121212;
|
18 |
padding: 20px;
|
19 |
color: white;
|
20 |
border: 1 px solid white;
|
|
|
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
|
|
|
42 |
items = data.get('items', [])
|
43 |
results = [item['snippet'] for item in items]
|
44 |
result_text = '\n'.join(results)
|
45 |
+
return results[0]
|
46 |
return result_text
|
47 |
|
48 |
# URL der Google Custom Search API
|