File size: 1,724 Bytes
a936419
 
 
8ca50ab
a936419
201f13e
f824e57
a07a31e
 
 
 
 
24ad0b1
a07a31e
 
24ad0b1
 
a07a31e
 
 
7ff4fbc
a07a31e
 
 
 
 
 
 
 
 
 
 
 
 
 
f824e57
5758366
2c9db66
f824e57
 
 
 
a936419
 
 
aee6311
7ff4fbc
aee6311
a936419
aee6311
a936419
5e3a028
a936419
33dc2c4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import gradio as gr
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin

def parse_links(prompt):
    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"contact details for {prompt}. output format=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())
        return response.json()
        # 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="Name des Vereins", value="Aero Club Bamberg")
    links_output = gr.JSON(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()