Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -21,12 +21,8 @@ custom_css = """
|
|
21 |
}
|
22 |
"""
|
23 |
|
24 |
-
def question(prompt):
|
25 |
-
|
26 |
-
Name=prompt
|
27 |
-
#outputs.value = "# Bitte warten"
|
28 |
-
#suite your prompt to your needs
|
29 |
-
anfrage ="""
|
30 |
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.
|
31 |
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.
|
32 |
{
|
@@ -37,8 +33,6 @@ def question(prompt):
|
|
37 |
}
|
38 |
"""
|
39 |
try:
|
40 |
-
#get Perplexica on github
|
41 |
-
#http:// url to perplexica api running inside a docker container. you may use certbot to issue a certificate for the perplexica webserver
|
42 |
url = secreturl
|
43 |
|
44 |
payload = {
|
@@ -50,9 +44,8 @@ def question(prompt):
|
|
50 |
"provider": "local",
|
51 |
"model": "xenova-bge-small-en-v1.5"
|
52 |
},
|
53 |
-
"optimizationMode":
|
54 |
"focusMode": "webSearch",
|
55 |
-
#"query": f"Impressum Name={prompt}\n{anfrage}. outputformat=json",
|
56 |
"query": f"antworte kurz und knapp. {prompt}. antworte auf deutsch. return plain text only für text zu sprache\n",
|
57 |
"history": [
|
58 |
["human", "Hi, how are you?"],
|
@@ -70,29 +63,25 @@ def question(prompt):
|
|
70 |
for i in range(1, 19):
|
71 |
ergebnis = ergebnis.replace(f"[{i}]", " ")
|
72 |
|
73 |
-
#ergebnis = gr.Markdown()
|
74 |
return ergebnis
|
75 |
-
# return as Dictionary, for gr.JSON
|
76 |
-
#return {"body_text": body_text}
|
77 |
|
78 |
except requests.RequestException as e:
|
79 |
return {"error": str(e)}
|
80 |
except Exception as e:
|
81 |
return {"error": str(e)}
|
82 |
|
83 |
-
#clear output
|
84 |
def clear():
|
85 |
-
|
86 |
-
return clear
|
87 |
|
88 |
# Erstelle die Gradio-Schnittstelle
|
89 |
-
with gr.Blocks(css=custom_css, theme
|
90 |
gr.Markdown("# Perplexica WebSearch <br>")
|
91 |
-
links_output = gr.Markdown(label="Antwort",elem_id="md")
|
92 |
-
ort_input = gr.Textbox(label="Frage", placeholder="ask anything...", scale=
|
93 |
-
|
94 |
button = gr.Button("senden", elem_id="senden")
|
95 |
-
button.click(fn=question, inputs=ort_input, outputs=links_output)
|
96 |
-
|
|
|
97 |
|
98 |
demo.launch()
|
|
|
21 |
}
|
22 |
"""
|
23 |
|
24 |
+
def question(prompt, optimization_mode):
|
25 |
+
anfrage = """
|
|
|
|
|
|
|
|
|
26 |
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.
|
27 |
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.
|
28 |
{
|
|
|
33 |
}
|
34 |
"""
|
35 |
try:
|
|
|
|
|
36 |
url = secreturl
|
37 |
|
38 |
payload = {
|
|
|
44 |
"provider": "local",
|
45 |
"model": "xenova-bge-small-en-v1.5"
|
46 |
},
|
47 |
+
"optimizationMode": optimization_mode,
|
48 |
"focusMode": "webSearch",
|
|
|
49 |
"query": f"antworte kurz und knapp. {prompt}. antworte auf deutsch. return plain text only für text zu sprache\n",
|
50 |
"history": [
|
51 |
["human", "Hi, how are you?"],
|
|
|
63 |
for i in range(1, 19):
|
64 |
ergebnis = ergebnis.replace(f"[{i}]", " ")
|
65 |
|
|
|
66 |
return ergebnis
|
|
|
|
|
67 |
|
68 |
except requests.RequestException as e:
|
69 |
return {"error": str(e)}
|
70 |
except Exception as e:
|
71 |
return {"error": str(e)}
|
72 |
|
|
|
73 |
def clear():
|
74 |
+
return "", "speed"
|
|
|
75 |
|
76 |
# Erstelle die Gradio-Schnittstelle
|
77 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as demo:
|
78 |
gr.Markdown("# Perplexica WebSearch <br>")
|
79 |
+
links_output = gr.Markdown(label="Antwort", elem_id="md")
|
80 |
+
ort_input = gr.Textbox(label="Frage", placeholder="ask anything...", scale=3, value="")
|
81 |
+
optimization_mode_input = gr.Dropdown(choices=["speed", "balanced"], label="Optimization Mode", value="speed")
|
82 |
button = gr.Button("senden", elem_id="senden")
|
83 |
+
button.click(fn=question, inputs=[ort_input, optimization_mode_input], outputs=links_output)
|
84 |
+
clear_button = gr.Button("clear", elem_id="clear")
|
85 |
+
clear_button.click(fn=clear, inputs=[], outputs=[ort_input, optimization_mode_input])
|
86 |
|
87 |
demo.launch()
|