Spaces:
Sleeping
Sleeping
Create frontend/app.py
Browse files- frontend/app.py +22 -0
frontend/app.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
API_URL = "http://localhost:8000" # Change to internal URL in Docker if needed
|
| 5 |
+
|
| 6 |
+
def add_task_ui(title):
|
| 7 |
+
response = requests.post(f"{API_URL}/tasks/", json={"id": "", "title": title, "completed": False})
|
| 8 |
+
return get_tasks_ui()
|
| 9 |
+
|
| 10 |
+
def get_tasks_ui():
|
| 11 |
+
response = requests.get(f"{API_URL}/tasks/")
|
| 12 |
+
return [f"{task['title']} - {'✔️' if task['completed'] else '❌'}" for task in response.json()]
|
| 13 |
+
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
with gr.Row():
|
| 16 |
+
task_input = gr.Textbox(label="New Task")
|
| 17 |
+
add_button = gr.Button("Add Task")
|
| 18 |
+
task_list = gr.Textbox(label="Tasks", lines=10)
|
| 19 |
+
|
| 20 |
+
add_button.click(add_task_ui, inputs=task_input, outputs=task_list)
|
| 21 |
+
|
| 22 |
+
demo.launch()
|