Spaces:
Sleeping
Sleeping
Create gradio_app.py
Browse files- gradio_app.py +22 -0
gradio_app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
|
4 |
+
BACKEND_URL = "http://127.0.0.1:8080" # your internal Flask app
|
5 |
+
|
6 |
+
def correct_text(paragraph):
|
7 |
+
try:
|
8 |
+
resp = requests.post(f"{BACKEND_URL}/correct_text", json={"paragraph": paragraph})
|
9 |
+
return resp.json().get("grammar_corrected", "Error occurred")
|
10 |
+
except Exception as e:
|
11 |
+
return f"Error: {str(e)}"
|
12 |
+
|
13 |
+
def chat_with_bot(message):
|
14 |
+
try:
|
15 |
+
resp = requests.post(f"{BACKEND_URL}/chat", json={"message": message})
|
16 |
+
data = resp.json()
|
17 |
+
return data.get("corrected_text", "Error occurred")
|
18 |
+
except Exception as e:
|
19 |
+
return f"Error: {str(e)}"
|
20 |
+
|
21 |
+
demo = gr.Interface(fn=correct_text, inputs="text", outputs="text", title="Paragraph Correction")
|
22 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|