cloudwp commited on
Commit
b9db857
·
verified ·
1 Parent(s): 7e6554b

Update frontend.py

Browse files
Files changed (1) hide show
  1. frontend.py +33 -4
frontend.py CHANGED
@@ -1,8 +1,37 @@
1
  import gradio as gr
 
2
 
3
- def greet(name):
4
- return f"Hello {name}!"
5
 
6
- gui = gr.Interface(fn=greet, inputs="text", outputs="text")
 
 
 
 
 
 
7
 
8
- gui.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()