File size: 3,539 Bytes
a936419
 
 
8ca50ab
1d3c45e
c9f3ae4
a936419
ce9fc94
c402c9e
55e7ed5
adfe721
ad7c5c6
 
b22d092
5fd5342
ad7c5c6
a224edc
 
5fd5342
ad7c5c6
c402c9e
 
 
fd1055b
2bc40b7
9d4773b
33d5e28
2bc40b7
a41bba5
c9b175d
 
a41bba5
2c076d1
a41bba5
 
 
 
 
f824e57
2bc40b7
 
9005e59
2bc40b7
a07a31e
 
 
2c076d1
a07a31e
 
24ad0b1
 
a07a31e
fd1055b
a07a31e
bb0ed10
d549d87
a07a31e
 
 
 
 
 
 
 
 
 
 
512941f
fd1055b
 
 
 
33ef355
543ccb3
5a96c14
5758366
2c9db66
f824e57
 
 
 
2bc40b7
 
2566216
5a96c14
 
a936419
 
67634bf
 
a640856
4cc0f9b
a640856
fd1055b
 
eeb9912
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
97
98
import gradio as gr
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin
import json
import os

secreturl = os.environ.get('secret_url')
custom_css = """
#md {
    height: 350px;  
    font-size: 30px;
    background: #121212;
    padding: 20px;
    padding-top: 40px;
    color: white;
}
#senden {
    width: 200px; 
    float: right;
}
"""

def question(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:)'
    Name=prompt
    #outputs.value = "# Bitte warten"
    #suite your prompt to your needs
    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:
        #get Perplexica on github
        #http:// url to perplexica api running inside a docker container. you may use certbot to issue a certificate for the perplexica webserver
        url = secreturl
        
        payload = {
            "chatModel": {
                "provider": "groq",
                "model": "llama3-70b-8192"
            },
            "embeddingModel": {
                "provider": "local",
                "model": "xenova-bge-small-en-v1.5"
            },
            "optimizationMode": "speed", #hier soll der wert stehen der ausgewählt wurd
            "focusMode": "webSearch",
            #"query": f"Impressum Name={prompt}\n{anfrage}. outputformat=json",
            "query": f"antworte kurz und knapp. {prompt}. antworte auf deutsch. return plain text only für text zu sprache\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, headers=headers)
        ergebnis = response.json().get('message')
        
        for i in range(1, 19):
            ergebnis = ergebnis.replace(f"[{i}]", " ")
            
        #ergebnis = gr.Markdown()
        return ergebnis
        # return as Dictionary, for gr.JSON 
        #return {"body_text": body_text}
    
    except requests.RequestException as e:
        return {"error": str(e)}
    except Exception as e:
        return {"error": str(e)}

#clear output
def clear():
    clear=""
    return clear

# Erstelle die Gradio-Schnittstelle
with gr.Blocks(css=custom_css, theme = gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as demo:
    gr.Markdown("# Perplexica WebSearch <br>")
    links_output = gr.Markdown(label="Antwort",elem_id="md")  
    ort_input = gr.Textbox(label="Frage", placeholder="ask anything...", scale= 3, value="")   
    #clearbutton = gr.Button("clear", elem_id="clear")  
    button = gr.Button("senden", elem_id="senden")   
    button.click(fn=question, inputs=ort_input, outputs=links_output)
    #clearbutton.click(fn=clear, inputs=[], outputs=links_output)

demo.launch()