Spaces:
Running
Running
File size: 3,915 Bytes
a936419 8ca50ab f54fd23 1d3c45e c9f3ae4 a936419 f54fd23 ce9fc94 c402c9e 55e7ed5 6abd1f2 ec21f86 a33fcfc b22d092 5fd5342 ad7c5c6 22dc62c a224edc e1dd5f0 c6fd5fb ad7c5c6 c6fd5fb c402c9e ec21f86 d18d4b3 e1dd5f0 d18d4b3 c402c9e c122019 c9b175d a41bba5 2c076d1 a41bba5 f824e57 2f43b55 2bc40b7 a07a31e 170e0ff a07a31e af2274b a07a31e c122019 a07a31e f54fd23 a07a31e 7b75542 41d775d 7b75542 fdc85b0 9481c3b fd1055b 543ccb3 2c9db66 f824e57 2bc40b7 2566216 c122019 a936419 c122019 b7315e2 ed6264a 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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
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: 500px;
font-size: 30px;
background: #121212;
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"
payload = {
"chatModel": {
"provider": "gemini",
"model": "gemini-1.5-flash"
},
"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)
try:
response.raise_for_status() # Überprüfen Sie, ob der Statuscode ein Fehler ist
result = response.json() # Versuchen Sie, die Antwort als JSON zu parsen
except ValueError:
return {"error": "Die Antwort konnte nicht als JSON geparst werden."}
except requests.RequestException as e:
return {"error": str(e)}
print("Serverantwort:", response.text) # Protokollieren Sie die rohe Antwort
return result
response = requests.post(url, json=payload, headers=headers)
#ergebnis = response.json().get('message')
result = response.json()
return result
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, theme=gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as demo:
#gr.Markdown("# <br>")
links_output = gr.Textbox(label="Antwort", elem_id="md", value="# Perplexica WebSearch")
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() |