import gradio as gr
import requests
# Backend API Base URL
API_BASE_URL = "http://localhost:5000"
# Funktion zur Analyse von Text über die API
def analyze_text(text, desired_length, synonym_api_key, grammar_api_key):
configure_payload = {
"synonym_api_key": synonym_api_key,
"grammar_api_key": grammar_api_key
}
requests.post(f"{API_BASE_URL}/configure", json=configure_payload)
analyze_payload = {"text": text, "desired_length": desired_length}
response = requests.post(f"{API_BASE_URL}/analyze-text", json=analyze_payload)
return response.json()
# Gradio-Interface
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.")
with gr.Row():
synonym_api_key = gr.Textbox(label="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")
analyze_button.click(fn=analyze_text, inputs=[input_text, desired_length, synonym_api_key, grammar_api_key], outputs=result_output)
# Starten der Gradio-Oberfläche
interface.launch()