File size: 3,181 Bytes
a936419
 
 
8ca50ab
f54fd23
1d3c45e
c9f3ae4
a936419
f54fd23
 
ce9fc94
c402c9e
55e7ed5
7a72130
47ea983
 
b22d092
5fd5342
ad7c5c6
22dc62c
a224edc
e1dd5f0
c6fd5fb
ad7c5c6
c6fd5fb
c402c9e
ec21f86
d18d4b3
e1dd5f0
 
d18d4b3
c402c9e
 
c122019
 
c9b175d
 
a41bba5
2c076d1
a41bba5
 
 
 
 
f824e57
500999a
2bc40b7
a07a31e
 
3b9fe27
83586b7
a07a31e
 
af2274b
 
a07a31e
c122019
a07a31e
f54fd23
a07a31e
 
 
 
 
 
 
 
 
 
7b75542
5a88752
e8f668c
 
5a88752
 
2c9db66
f824e57
 
 
 
2bc40b7
2566216
c122019
a936419
 
47ea983
b7315e2
f0a4b23
c122019
 
e1dd5f0
e100c65
c2d9657
 
a936419
ece9550
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import gradio as gr
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin
from datetime import datetime
import json
import os

jetzt = datetime.now()
zeitstempel_str = jetzt.strftime("%Y-%m-%d")
secreturl = os.environ.get('secret_url')
custom_css = """
#md {
    height: 450px;  
    font-size: 35px;
    background: black;
    padding: 20px;
    padding-top: 40px;
    color: white;
    border: 1 px solid #383838;
}
.senden {
    width: 300px; 
    float: right;
    background:purple;
}
.clear-button {
    float: right;
    #margin-top: 10px;
    background:purple;
}
"""

def question(prompt, optimization_mode):
    anfrage = """
    instruction: you are a json expert and your job is extracting information from text, generating valid json and return a json object only. do not return any text. halte dich an das vorgegebene json schema.
    prompt: fill in the missing contact information. do not reference the json object. do not use html tags inside the json object. do not return explanaitons or any other text. return a valid json object only.
    {
      "Name": "",
      "Email": "",
      "Website": "",
      "Phone": ""
    }
    """
    try:
        url = "http://185.248.140.121:3001/api/search"
        
        payload = {
            "chatModel": {
                "provider": "groq",
                "model": "llama3-70b-8192"
            },
            "embeddingModel": {
                "provider": "gemini",
                "model": "text-embedding-004"
            },
            "optimizationMode": optimization_mode,
            "focusMode": "webSearch",
            "query": f"antworte kurz und knapp. {prompt}. antworte auf deutsch. formatiere deine antworten ansprechend und strukturiert in markdown\nhinweis: heute ist der {zeitstempel_str}\n",
            "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)
        ergebnis = response.json().get('message')  
        for i in range(1, 19):
            ergebnis = ergebnis.replace(f"[{i}]", " ")
            
        return ergebnis
    
    except requests.RequestException as e:
        return {"error": str(e)}
    except Exception as e:
        return {"error": str(e)}

def clear():
    return "", "speed"

# Erstelle die Gradio-Schnittstelle
with gr.Blocks(css=custom_css) as demo:
    #gr.Markdown("#  <br>")
    links_output = gr.Markdown(label="Antwort", elem_id="md", value="")  
    ort_input = gr.Textbox(label="Frage", placeholder="ask anything...", scale=3, value="")   
    optimization_mode_input = gr.Dropdown(choices=["speed", "balanced"], label="Optimization Mode", value="speed")
    button = gr.Button("senden", elem_classes="senden")   
    button.click(fn=question, inputs=[ort_input, optimization_mode_input], outputs=links_output)
    #clear_button = gr.Button("clear", elem_classes="clear-button")  
    #clear_button.click(fn=clear, inputs=[], outputs=[ort_input, optimization_mode_input])

demo.launch()