Spaces:
Running
Running
File size: 2,703 Bytes
a936419 8ca50ab f54fd23 a70ebce 3009aec a936419 f54fd23 ce9fc94 c402c9e 55e7ed5 7a72130 47ea983 b22d092 5fd5342 ad7c5c6 22dc62c a224edc c402c9e c122019 3009aec f824e57 8010aa4 3009aec 2bc40b7 a07a31e 3b9fe27 83586b7 a07a31e af2274b a07a31e c122019 a07a31e f54fd23 a07a31e 7b75542 3009aec e8f668c 3009aec a70ebce 5a88752 2c9db66 f824e57 2bc40b7 2566216 c122019 a936419 47ea983 c3a7014 c122019 c2eaaca e2c92df 9c8d058 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 |
import gradio as gr
import requests
from urllib.parse import urljoin
from datetime import datetime
from IPython.display import display
from IPython.display import Markdown
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;
}
"""
def question(prompt, optimization_mode):
try:
# url to the Perplexica backend (http://url.com:3001/api search/)
url = secreturl
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')
#get rid of some disturbing numbers
for i in range(1, 19):
ergebnis = ergebnis.replace(f"[{i}]", " ")
#this modul is sooooo cool:)
display(Markdown(ergebnis))
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:
links_output = gr.Markdown(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="balanced")
ort_input.submit(fn=question, inputs=[ort_input, optimization_mode_input], outputs=links_output)
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)
demo.launch() |