import gradio as gr
import requests
# Backend API URL
API_BASE_URL = "http://localhost:5000"
# Funktion zur Analyse von Text über die API
def analyze_text(text, desired_length, language, synonym_api_key, grammar_api_key):
# Konfiguration der APIs
configure_payload = {
"synonym_primary_api_key": synonym_api_key,
"grammar_api_key": grammar_api_key
}
requests.post(f"{API_BASE_URL}/configure", json=configure_payload)
# Analyse des Textes
analyze_payload = {"text": text, "desired_length": desired_length, "language": language}
response = requests.post(f"{API_BASE_URL}/analyze-text", json=analyze_payload)
return response.json()
# Gradio-Interface erstellen
with gr.Blocks() as interface:
gr.Markdown("
Textanpassungstool
")
with gr.Row():
input_text = gr.Textbox(label="Eingabetext", placeholder="Geben Sie hier den Text ein.")
desired_length = gr.Number(label="Gewünschte Zeichenanzahl", placeholder="Ziel-Zeichenanzahl.")
language = gr.Dropdown(choices=["en", "de", "fr"], label="Sprache")
with gr.Row():
synonym_api_key = gr.Textbox(label="Primärer Synonym-API-Schlüssel")
grammar_api_key = gr.Textbox(label="Grammatik API-Schlüssel")
analyze_button = gr.Button("Text analysieren")
result_output = gr.JSON(label="Ergebnisse")
# Klick-Interaktion
analyze_button.click(fn=analyze_text, inputs=[input_text, desired_length, language, synonym_api_key, grammar_api_key], outputs=result_output)
# Starten der Gradio-Oberfläche
interface.launch()