Spaces:
Runtime error
Runtime error
Create frontend.py
Browse files- frontend.py +37 -0
frontend.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
# Backend API Base URL
|
| 5 |
+
API_BASE_URL = "http://localhost:5000"
|
| 6 |
+
|
| 7 |
+
# Funktion zur Analyse von Text über die API
|
| 8 |
+
def analyze_text(text, desired_length, synonym_api_key, grammar_api_key):
|
| 9 |
+
configure_payload = {
|
| 10 |
+
"synonym_api_key": synonym_api_key,
|
| 11 |
+
"grammar_api_key": grammar_api_key
|
| 12 |
+
}
|
| 13 |
+
requests.post(f"{API_BASE_URL}/configure", json=configure_payload)
|
| 14 |
+
|
| 15 |
+
analyze_payload = {"text": text, "desired_length": desired_length}
|
| 16 |
+
response = requests.post(f"{API_BASE_URL}/analyze-text", json=analyze_payload)
|
| 17 |
+
return response.json()
|
| 18 |
+
|
| 19 |
+
# Gradio-Interface
|
| 20 |
+
with gr.Blocks() as interface:
|
| 21 |
+
gr.Markdown("<h1>Textanpassungstool</h1>")
|
| 22 |
+
|
| 23 |
+
with gr.Row():
|
| 24 |
+
input_text = gr.Textbox(label="Eingabetext", placeholder="Geben Sie hier den Text ein.")
|
| 25 |
+
desired_length = gr.Number(label="Gewünschte Zeichenanzahl", placeholder="Ziel-Zeichenanzahl.")
|
| 26 |
+
|
| 27 |
+
with gr.Row():
|
| 28 |
+
synonym_api_key = gr.Textbox(label="Synonym API-Schlüssel")
|
| 29 |
+
grammar_api_key = gr.Textbox(label="Grammatik API-Schlüssel")
|
| 30 |
+
|
| 31 |
+
analyze_button = gr.Button("Text analysieren")
|
| 32 |
+
result_output = gr.JSON(label="Ergebnisse")
|
| 33 |
+
|
| 34 |
+
analyze_button.click(fn=analyze_text, inputs=[input_text, desired_length, synonym_api_key, grammar_api_key], outputs=result_output)
|
| 35 |
+
|
| 36 |
+
# Starten der Gradio-Oberfläche
|
| 37 |
+
interface.launch()
|