magic-todo / app.py
rm-dev-null's picture
Update app.py
bdb1796 verified
import gradio as gr
from huggingface_hub import InferenceClient
import json
import time
class MagicTodo:
def __init__(self):
self.todos = []
self.client = None
self.history = []
self.current_index = -1
def set_model(self, model_name: str) -> str:
try:
self.client = InferenceClient(model_name)
return f"Modell erfolgreich gesetzt: {model_name}"
except Exception as e:
return f"Fehler beim Setzen des Modells: {str(e)}"
async def break_down_task(self, task: str, spiciness: int) -> list:
if not self.client:
return "Kein Modell ausgewählt"
prompt = f"""Zerlege folgende Aufgabe in {spiciness * 2} konkrete Unteraufgaben:
Aufgabe: {task}
Format: Liste von Unteraufgaben, eine pro Zeile
Wichtig: Gib nur die Unteraufgaben zurück."""
try:
response = await self.client.text_generation(
prompt,
max_new_tokens=200,
temperature=0.7,
top_p=0.95
)
return [s.strip() for s in response.split('\n') if s.strip()]
except Exception as e:
return f"Fehler beim Zerlegen: {str(e)}"
def create_ui():
with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue")) as demo:
todo = MagicTodo()
# Header
gr.Markdown("# Magic ToDo")
gr.Markdown("## Breaking things down so you don't.")
# Model Selection
with gr.Row():
model_input = gr.Textbox(
label="Hugging Face Modell",
placeholder="z.B. HuggingFaceH4/zephyr-7b-beta",
value="HuggingFaceH4/zephyr-7b-beta"
)
set_model_btn = gr.Button("Modell setzen")
# Task Input
with gr.Row():
task_input = gr.Textbox(
label="Item",
placeholder="Add new item..."
)
spiciness = gr.Slider(
minimum=1,
maximum=5,
value=3,
step=1,
label="Spiciness Level 🌶️"
)
add_btn = gr.Button("➕")
# Task Display
task_list = gr.Dataframe(
headers=["Task", "Spiciness", "Status"],
interactive=True
)
# Action Buttons
with gr.Row():
sync_btn = gr.Button("🔄 Sync")
export_btn = gr.Button("📤 Export")
undo_btn = gr.Button("↩️ Undo")
redo_btn = gr.Button("↪️ Redo")
# Event handlers
set_model_btn.click(
fn=todo.set_model,
inputs=[model_input],
outputs=[gr.Textbox(label="Status")]
)
add_btn.click(
fn=lambda x, y: todo.add_task(x, y),
inputs=[task_input, spiciness],
outputs=[task_list]
)
# CSS für das Design
demo.load(css="""
.gradio-container {
max-width: 800px !important;
margin: auto !important;
}
.task-item {
display: flex;
align-items: center;
padding: 0.5rem;
border: 1px solid var(--border-color-primary);
border-radius: 4px;
margin-bottom: 0.5rem;
}
.spiciness-indicator {
font-size: 1.2rem;
margin-left: 0.5rem;
}
""")
return demo
if __name__ == "__main__":
demo = create_ui()
demo.launch(debug=True)