Spaces:
Running
Running
import gradio as gr | |
import requests | |
from bs4 import BeautifulSoup | |
from urllib.parse import urljoin | |
def parse_links(prompt): | |
#anfrage ='fill in the missing contact information. do not reference the json object. do not use html tags inside the json object. it must be valid json. do not return explanaitons or any other text. thanks for your efforts:)' | |
try: | |
url = "http://specialist-it.de:3001/api/search" | |
payload = { | |
"chatModel": { | |
"provider": "groq", | |
"model": "mixtral-8x7b-32768" | |
}, | |
"embeddingModel": { | |
"provider": "local", | |
"model": "xenova-bge-small-en-v1.5" | |
}, | |
"optimizationMode": "balanced", | |
"focusMode": "webSearch", | |
"query": f"{prompt}. outputformat=json", | |
"history": [ | |
["human", "Hi, how are you?"], | |
["assistant", "I am doing well, how can I help you today?"] | |
] | |
} | |
headers = { | |
"Content-Type": "application/json" | |
} | |
response = requests.post(url, json=payload, headers=headers) | |
print(response.json()) | |
# Parse the JSON response | |
#data = response.json() | |
# Extract the message | |
#ergebnis = data.get('message') | |
#return ergebnis | |
return response.json().get('message') | |
# Rückgabe als Dictionary, um es mit gr.JSON kompatibel zu machen | |
#return {"body_text": body_text} | |
except requests.RequestException as e: | |
return {"error": str(e)} | |
except Exception as e: | |
return {"error": str(e)} | |
# Erstelle die Gradio-Schnittstelle | |
with gr.Blocks() as demo: | |
gr.Markdown("# Perplexica WebSearch") | |
ort_input = gr.Textbox(label="Prompt", placeholder="prompt", value="contact details Aero Club Bamberg e.v.") | |
links_output = gr.Textbox(label="Antwort") | |
# Button zum Starten der Parsung | |
button = gr.Button("senden") | |
# Verbinde den Button mit der Funktion | |
button.click(fn=parse_links, inputs=ort_input, outputs=links_output) | |
demo.launch() |