Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,24 @@ import gradio as gr
|
|
2 |
from googlesearch import search
|
3 |
import requests
|
4 |
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
def google_search(query):
|
7 |
headers = {
|
@@ -10,20 +28,14 @@ def google_search(query):
|
|
10 |
# Führt die Suche durch und erhält das erste Ergebnis
|
11 |
for result in search(query, num_results=1):
|
12 |
url = result
|
13 |
-
#return url
|
14 |
break
|
15 |
|
16 |
-
# Holt den Inhalt der Webseite
|
17 |
response = requests.get(url)
|
18 |
soup = BeautifulSoup(response.text, 'html.parser')
|
19 |
#first_div = soup.find('div', class_='MjjYud')
|
20 |
first_div = soup.find('body')
|
21 |
|
22 |
-
|
23 |
-
return first_div.text.strip()
|
24 |
-
else:
|
25 |
-
print("Kein div mit der Klasse 'MjjYud' gefunden.")
|
26 |
-
return None
|
27 |
|
28 |
demo = gr.Interface(
|
29 |
fn=google_search,
|
|
|
2 |
from googlesearch import search
|
3 |
import requests
|
4 |
from bs4 import BeautifulSoup
|
5 |
+
from gradio_client import Client
|
6 |
+
import groq
|
7 |
+
|
8 |
+
api_key = os.getenv('groq')
|
9 |
+
client = groq.Client(api_key=api_key)
|
10 |
+
|
11 |
+
def llm(message):
|
12 |
+
try:
|
13 |
+
completion = client.chat.completions.create(
|
14 |
+
model="Mixtral-8x7b-32768",
|
15 |
+
messages=[
|
16 |
+
{"role": "system", "content": "You are a helpful assistant."},
|
17 |
+
{"role": "user", "content": f"{message}. antworte immer auf deutsch"}
|
18 |
+
],
|
19 |
+
)
|
20 |
+
return completion.choices[0].message.content
|
21 |
+
except Exception as e:
|
22 |
+
return f"Error in response generation: {str(e)}"
|
23 |
|
24 |
def google_search(query):
|
25 |
headers = {
|
|
|
28 |
# Führt die Suche durch und erhält das erste Ergebnis
|
29 |
for result in search(query, num_results=1):
|
30 |
url = result
|
|
|
31 |
break
|
32 |
|
|
|
33 |
response = requests.get(url)
|
34 |
soup = BeautifulSoup(response.text, 'html.parser')
|
35 |
#first_div = soup.find('div', class_='MjjYud')
|
36 |
first_div = soup.find('body')
|
37 |
|
38 |
+
return first_div.text.strip()
|
|
|
|
|
|
|
|
|
39 |
|
40 |
demo = gr.Interface(
|
41 |
fn=google_search,
|