Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -48,57 +48,31 @@ def predict(prompt):
|
|
48 |
return response_value
|
49 |
return response
|
50 |
|
51 |
-
def
|
52 |
|
53 |
headers = {
|
54 |
"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"
|
55 |
}
|
56 |
-
|
57 |
-
#search_results = google_search(search_term)
|
58 |
-
url = f"https://www.google.com/search?q=mpressum {search_term}"
|
59 |
response = requests.get(url, headers=headers)
|
60 |
soup = BeautifulSoup(response.content, 'html.parser')
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
return
|
65 |
-
|
66 |
-
def websearch(prompt):
|
67 |
-
|
68 |
-
url = f"https://www.google.com/search?q={prompt}"
|
69 |
-
headers = {
|
70 |
-
"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"
|
71 |
-
}
|
72 |
-
|
73 |
-
try:
|
74 |
-
response = requests.get(url, headers=headers)
|
75 |
-
response.raise_for_status() # Wirft eine Exception für Fehlercodes
|
76 |
-
except requests.exceptions.RequestException as e:
|
77 |
-
print(f"Fehler beim Abrufen der Google-Seite: {e}")
|
78 |
-
return None
|
79 |
-
|
80 |
-
soup = BeautifulSoup(response.content, 'html.parser')
|
81 |
-
|
82 |
-
first_div = soup.find('div', class_='MjjYud')
|
83 |
-
|
84 |
-
if first_div:
|
85 |
-
return first_div.text.strip()
|
86 |
-
else:
|
87 |
-
print("Kein div mit der Klasse 'MjjYud' gefunden.")
|
88 |
-
return None
|
89 |
|
90 |
# Create the Gradio interface
|
91 |
with gr.Blocks(css=custom_css) as demo:
|
92 |
with gr.Row():
|
93 |
-
|
94 |
-
details_output = gr.Textbox(label="Ausgabe", value = f"\n\n\n\n")
|
95 |
with gr.Row():
|
96 |
ort_input = gr.Textbox(label="prompt", placeholder="ask anything...")
|
97 |
with gr.Row():
|
98 |
button = gr.Button("Senden")
|
99 |
|
100 |
# Connect the button to the function
|
101 |
-
button.click(fn=
|
102 |
|
103 |
# Launch the Gradio application
|
104 |
demo.launch()
|
|
|
48 |
return response_value
|
49 |
return response
|
50 |
|
51 |
+
def websearch(search_term):
|
52 |
|
53 |
headers = {
|
54 |
"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"
|
55 |
}
|
56 |
+
url = f"https://www.google.com/search?q={search_term}"
|
|
|
|
|
57 |
response = requests.get(url, headers=headers)
|
58 |
soup = BeautifulSoup(response.content, 'html.parser')
|
59 |
+
response_text = soup.find('body')
|
60 |
+
#result = predict(response_text.text)
|
61 |
+
#first_div = soup.find('div', class_='MjjYud')
|
62 |
+
return response_text.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
# Create the Gradio interface
|
65 |
with gr.Blocks(css=custom_css) as demo:
|
66 |
with gr.Row():
|
67 |
+
details_output = gr.Markdown(label="answer", elem_id="md")
|
68 |
+
#details_output = gr.Textbox(label="Ausgabe", value = f"\n\n\n\n")
|
69 |
with gr.Row():
|
70 |
ort_input = gr.Textbox(label="prompt", placeholder="ask anything...")
|
71 |
with gr.Row():
|
72 |
button = gr.Button("Senden")
|
73 |
|
74 |
# Connect the button to the function
|
75 |
+
button.click(fn=websearch, inputs=ort_input, outputs=details_output)
|
76 |
|
77 |
# Launch the Gradio application
|
78 |
demo.launch()
|