Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
from bs4 import BeautifulSoup
|
4 |
from urllib.parse import urljoin
|
5 |
from datetime import datetime
|
6 |
-
import json
|
7 |
-
import os
|
8 |
from IPython.display import display
|
9 |
from IPython.display import Markdown
|
|
|
|
|
10 |
|
11 |
jetzt = datetime.now()
|
12 |
zeitstempel_str = jetzt.strftime("%Y-%m-%d")
|
@@ -21,31 +20,13 @@ custom_css = """
|
|
21 |
color: white;
|
22 |
border: 1 px solid #383838;
|
23 |
}
|
24 |
-
.senden {
|
25 |
-
width: 300px;
|
26 |
-
float: right;
|
27 |
-
background:purple;
|
28 |
-
}
|
29 |
-
.clear-button {
|
30 |
-
float: right;
|
31 |
-
#margin-top: 10px;
|
32 |
-
background:purple;
|
33 |
-
}
|
34 |
"""
|
35 |
|
36 |
def question(prompt, optimization_mode):
|
37 |
-
|
38 |
-
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.
|
39 |
-
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.
|
40 |
-
{
|
41 |
-
"Name": "",
|
42 |
-
"Email": "",
|
43 |
-
"Website": "",
|
44 |
-
"Phone": ""
|
45 |
-
}
|
46 |
-
"""
|
47 |
try:
|
48 |
-
url
|
|
|
49 |
|
50 |
payload = {
|
51 |
"chatModel": {
|
@@ -70,10 +51,11 @@ def question(prompt, optimization_mode):
|
|
70 |
}
|
71 |
|
72 |
response = requests.post(url, json=payload)
|
73 |
-
ergebnis = response.json().get('message')
|
|
|
74 |
for i in range(1, 19):
|
75 |
ergebnis = ergebnis.replace(f"[{i}]", " ")
|
76 |
-
|
77 |
display(Markdown(ergebnis))
|
78 |
return ergebnis
|
79 |
|
@@ -82,21 +64,15 @@ def question(prompt, optimization_mode):
|
|
82 |
except Exception as e:
|
83 |
return {"error": str(e)}
|
84 |
|
85 |
-
|
86 |
def clear():
|
87 |
return "", "speed"
|
88 |
|
89 |
# Erstelle die Gradio-Schnittstelle
|
90 |
with gr.Blocks(css=custom_css) as demo:
|
91 |
-
#gr.Markdown("# Perplexica Websearch")
|
92 |
links_output = gr.Markdown(label="Antwort", elem_id="md", value="# Perplexica Websearch")
|
93 |
ort_input = gr.Textbox(label="Frage", placeholder="ask anything...", scale=3, value="")
|
94 |
optimization_mode_input = gr.Dropdown(choices=["speed", "balanced"], label="Optimization Mode", value="balanced")
|
95 |
-
#button = gr.Button("senden", elem_classes="senden")
|
96 |
-
#button.click(fn=question, inputs=[ort_input, optimization_mode_input], outputs=links_output)
|
97 |
ort_input.submit(fn=question, inputs=[ort_input, optimization_mode_input], outputs=links_output)
|
98 |
examples = gr.Examples([["Erstelle eine Anleitung. Apache als reverse proxy installieren unter ubuntu 24.x"], ["Kontaktdaten Bürgermeister bad kissingen"], ["Kontaktdaten lachfalten bad kissingen. output format:json"]], ort_input)
|
99 |
-
#clear_button = gr.Button("clear", elem_classes="clear-button")
|
100 |
-
#clear_button.click(fn=clear, inputs=[], outputs=[ort_input, optimization_mode_input])
|
101 |
|
102 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
from urllib.parse import urljoin
|
4 |
from datetime import datetime
|
|
|
|
|
5 |
from IPython.display import display
|
6 |
from IPython.display import Markdown
|
7 |
+
import json
|
8 |
+
import os
|
9 |
|
10 |
jetzt = datetime.now()
|
11 |
zeitstempel_str = jetzt.strftime("%Y-%m-%d")
|
|
|
20 |
color: white;
|
21 |
border: 1 px solid #383838;
|
22 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
"""
|
24 |
|
25 |
def question(prompt, optimization_mode):
|
26 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
try:
|
28 |
+
# the url to the Perplexity backend (http://url.com:3001/api search/)
|
29 |
+
url = secreturl
|
30 |
|
31 |
payload = {
|
32 |
"chatModel": {
|
|
|
51 |
}
|
52 |
|
53 |
response = requests.post(url, json=payload)
|
54 |
+
ergebnis = response.json().get('message')
|
55 |
+
#get rid of some disturbing numbers
|
56 |
for i in range(1, 19):
|
57 |
ergebnis = ergebnis.replace(f"[{i}]", " ")
|
58 |
+
#this modul is sooooo cool:)
|
59 |
display(Markdown(ergebnis))
|
60 |
return ergebnis
|
61 |
|
|
|
64 |
except Exception as e:
|
65 |
return {"error": str(e)}
|
66 |
|
|
|
67 |
def clear():
|
68 |
return "", "speed"
|
69 |
|
70 |
# Erstelle die Gradio-Schnittstelle
|
71 |
with gr.Blocks(css=custom_css) as demo:
|
|
|
72 |
links_output = gr.Markdown(label="Antwort", elem_id="md", value="# Perplexica Websearch")
|
73 |
ort_input = gr.Textbox(label="Frage", placeholder="ask anything...", scale=3, value="")
|
74 |
optimization_mode_input = gr.Dropdown(choices=["speed", "balanced"], label="Optimization Mode", value="balanced")
|
|
|
|
|
75 |
ort_input.submit(fn=question, inputs=[ort_input, optimization_mode_input], outputs=links_output)
|
76 |
examples = gr.Examples([["Erstelle eine Anleitung. Apache als reverse proxy installieren unter ubuntu 24.x"], ["Kontaktdaten Bürgermeister bad kissingen"], ["Kontaktdaten lachfalten bad kissingen. output format:json"]], ort_input)
|
|
|
|
|
77 |
|
78 |
demo.launch()
|