test090309a commited on
Commit
f6c211e
·
verified ·
1 Parent(s): ece9998

ohne gradio

Browse files
Files changed (1) hide show
  1. app.py +49 -4
app.py CHANGED
@@ -1,6 +1,51 @@
1
- import gradio as gr
 
 
2
 
3
- def hello(name):
4
- return f"Hallo, {name}!"
5
 
6
- gr.Interface(fn=hello, inputs="text", outputs="text").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ from typing import List, Optional
4
 
5
+ app = FastAPI()
 
6
 
7
+ class Task(BaseModel):
8
+ id: int
9
+ title: str
10
+ description: Optional[str] = None
11
+ done: bool = False
12
+
13
+ tasks: List[Task] = []
14
+
15
+ @app.get("/")
16
+ def root():
17
+ return {"message": "Willkommen bei der ToDo-API! Siehe /tasks"}
18
+
19
+ @app.get("/tasks", response_model=List[Task])
20
+ def get_tasks():
21
+ return tasks
22
+
23
+ @app.post("/tasks", response_model=Task)
24
+ def create_task(task: Task):
25
+ if any(t.id == task.id for t in tasks):
26
+ raise HTTPException(status_code=400, detail="ID existiert bereits.")
27
+ tasks.append(task)
28
+ return task
29
+
30
+ @app.get("/tasks/{task_id}", response_model=Task)
31
+ def get_task(task_id: int):
32
+ for task in tasks:
33
+ if task.id == task_id:
34
+ return task
35
+ raise HTTPException(status_code=404, detail="Aufgabe nicht gefunden.")
36
+
37
+ @app.put("/tasks/{task_id}/done", response_model=Task)
38
+ def mark_task_done(task_id: int):
39
+ for task in tasks:
40
+ if task.id == task_id:
41
+ task.done = True
42
+ return task
43
+ raise HTTPException(status_code=404, detail="Aufgabe nicht gefunden.")
44
+
45
+ @app.delete("/tasks/{task_id}")
46
+ def delete_task(task_id: int):
47
+ for i, task in enumerate(tasks):
48
+ if task.id == task_id:
49
+ del tasks[i]
50
+ return {"detail": "Aufgabe gelöscht."}
51
+ raise HTTPException(status_code=404, detail="Aufgabe nicht gefunden.")