File size: 729 Bytes
f9b8f03
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
import requests

API_URL = "http://localhost:8000"  # Change to internal URL in Docker if needed

def add_task_ui(title):
    response = requests.post(f"{API_URL}/tasks/", json={"id": "", "title": title, "completed": False})
    return get_tasks_ui()

def get_tasks_ui():
    response = requests.get(f"{API_URL}/tasks/")
    return [f"{task['title']} - {'✔️' if task['completed'] else '❌'}" for task in response.json()]

with gr.Blocks() as demo:
    with gr.Row():
        task_input = gr.Textbox(label="New Task")
        add_button = gr.Button("Add Task")
    task_list = gr.Textbox(label="Tasks", lines=10)
    
    add_button.click(add_task_ui, inputs=task_input, outputs=task_list)

demo.launch()