Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
app = FastAPI()
|
@@ -42,7 +42,45 @@ def generate_quiz(context):
|
|
42 |
|
43 |
return response
|
44 |
|
45 |
-
@app.
|
46 |
-
async def
|
47 |
-
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Form
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
app = FastAPI()
|
|
|
42 |
|
43 |
return response
|
44 |
|
45 |
+
@app.get("/", response_class=HTMLResponse)
|
46 |
+
async def get_index():
|
47 |
+
return """
|
48 |
+
<!DOCTYPE html>
|
49 |
+
<html lang="en">
|
50 |
+
<head>
|
51 |
+
<meta charset="UTF-8">
|
52 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
53 |
+
<title>Generate Quiz</title>
|
54 |
+
</head>
|
55 |
+
<body>
|
56 |
+
<h2>Generate Quiz</h2>
|
57 |
+
<form action="/generate-quiz" method="post">
|
58 |
+
<label for="context">Context:</label><br>
|
59 |
+
<textarea id="context" name="context" rows="4" cols="50" required></textarea><br><br>
|
60 |
+
<input type="submit" value="Generate Quiz">
|
61 |
+
</form>
|
62 |
+
</body>
|
63 |
+
</html>
|
64 |
+
"""
|
65 |
+
|
66 |
+
@app.post("/generate-quiz", response_class=HTMLResponse)
|
67 |
+
async def generate_quiz_endpoint(context: str = Form(...)):
|
68 |
+
response = await generate_quiz(context)
|
69 |
+
|
70 |
+
quiz_html = f"""
|
71 |
+
<!DOCTYPE html>
|
72 |
+
<html lang="en">
|
73 |
+
<head>
|
74 |
+
<meta charset="UTF-8">
|
75 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
76 |
+
<title>Generated Quiz</title>
|
77 |
+
</head>
|
78 |
+
<body>
|
79 |
+
<h2>Generated Quiz</h2>
|
80 |
+
<pre>{response}</pre>
|
81 |
+
<p><a href="/">Back to generate another quiz</a></p>
|
82 |
+
</body>
|
83 |
+
</html>
|
84 |
+
"""
|
85 |
+
|
86 |
+
return HTMLResponse(content=quiz_html)
|