Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,6 +21,34 @@ custom_css = """
|
|
21 |
}
|
22 |
"""
|
23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
def websearch(prompt):
|
26 |
|
@@ -82,7 +110,7 @@ with gr.Blocks(css=custom_css) as demo:
|
|
82 |
button = gr.Button("Senden")
|
83 |
|
84 |
# Connect the button to the function
|
85 |
-
button.click(fn=
|
86 |
|
87 |
# Launch the Gradio application
|
88 |
demo.launch()
|
|
|
21 |
}
|
22 |
"""
|
23 |
|
24 |
+
def google_search(search_term, **kwargs):
|
25 |
+
service = build("customsearch", "v1", developerKey=api_key) # Ersetze YOUR_GOOGLE_API_KEY mit deinem API-Key
|
26 |
+
res = service.cse().list(q=search_term, cx="77f1602c0ff764edb", **kwargs).execute() # Ersetze YOUR_CUSTOM_SEARCH_ENGINE_ID mit deiner Custom Search Engine ID
|
27 |
+
return res
|
28 |
+
|
29 |
+
def get_impressum_text(search_term):
|
30 |
+
try:
|
31 |
+
search_results = google_search(search_term)
|
32 |
+
|
33 |
+
if 'items' in search_results:
|
34 |
+
for item in search_results['items']:
|
35 |
+
link = item['link']
|
36 |
+
try:
|
37 |
+
response = requests.get(link, timeout=5) # Timeout hinzugefügt für Fehlerbehandlung
|
38 |
+
response.raise_for_status() # Wirft eine Exception, wenn der Statuscode nicht 200 ist
|
39 |
+
soup = BeautifulSoup(response.content, 'html.parser')
|
40 |
+
|
41 |
+
impressum_div = soup.find('div', class_='MjjYud')
|
42 |
+
|
43 |
+
if impressum_div:
|
44 |
+
return impressum_div.text.strip()
|
45 |
+
|
46 |
+
except requests.exceptions.RequestException as e:
|
47 |
+
print(f"Fehler beim Abrufen der URL {link}: {e}")
|
48 |
+
continue # Weiter mit dem nächsten Suchergebnis
|
49 |
+
|
50 |
+
return None # Kein Impressum gefunden
|
51 |
+
|
52 |
|
53 |
def websearch(prompt):
|
54 |
|
|
|
110 |
button = gr.Button("Senden")
|
111 |
|
112 |
# Connect the button to the function
|
113 |
+
button.click(fn=get_impressum_text, inputs=ort_input, outputs=details_output)
|
114 |
|
115 |
# Launch the Gradio application
|
116 |
demo.launch()
|