Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
from
|
2 |
from fastapi.responses import HTMLResponse
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
-
app =
|
6 |
|
7 |
|
8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
@@ -43,8 +43,31 @@ def generate_quiz(context):
|
|
43 |
|
44 |
return response
|
45 |
|
46 |
-
@app.
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
return """
|
49 |
<!DOCTYPE html>
|
50 |
<html lang="en">
|
@@ -55,7 +78,7 @@ async def get_index():
|
|
55 |
</head>
|
56 |
<body>
|
57 |
<h2>Generate Quiz</h2>
|
58 |
-
<form action="/
|
59 |
<label for="context">Context:</label><br>
|
60 |
<textarea id="context" name="context" rows="4" cols="50" required></textarea><br><br>
|
61 |
<input type="submit" value="Generate Quiz">
|
@@ -64,24 +87,5 @@ async def get_index():
|
|
64 |
</html>
|
65 |
"""
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
response = await generate_quiz(context)
|
70 |
-
|
71 |
-
quiz_html = f"""
|
72 |
-
<!DOCTYPE html>
|
73 |
-
<html lang="en">
|
74 |
-
<head>
|
75 |
-
<meta charset="UTF-8">
|
76 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
77 |
-
<title>Generated Quiz</title>
|
78 |
-
</head>
|
79 |
-
<body>
|
80 |
-
<h2>Generated Quiz</h2>
|
81 |
-
<pre>{response}</pre>
|
82 |
-
<p><a href="/">Back to generate another quiz</a></p>
|
83 |
-
</body>
|
84 |
-
</html>
|
85 |
-
"""
|
86 |
-
|
87 |
-
return HTMLResponse(content=quiz_html)
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
from fastapi.responses import HTMLResponse
|
3 |
from huggingface_hub import InferenceClient
|
4 |
|
5 |
+
app = Flask(__name__)
|
6 |
|
7 |
|
8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
|
|
|
43 |
|
44 |
return response
|
45 |
|
46 |
+
@app.route("/", methods=["GET", "POST"])
|
47 |
+
def generate_quiz_page():
|
48 |
+
if request.method == "POST":
|
49 |
+
context = request.form.get("context")
|
50 |
+
response = generate_quiz(context)
|
51 |
+
|
52 |
+
quiz_html = f"""
|
53 |
+
<!DOCTYPE html>
|
54 |
+
<html lang="en">
|
55 |
+
<head>
|
56 |
+
<meta charset="UTF-8">
|
57 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
58 |
+
<title>Generated Quiz</title>
|
59 |
+
</head>
|
60 |
+
<body>
|
61 |
+
<h2>Generated Quiz</h2>
|
62 |
+
<pre>{response}</pre>
|
63 |
+
<p><a href="/">Back to generate another quiz</a></p>
|
64 |
+
</body>
|
65 |
+
</html>
|
66 |
+
"""
|
67 |
+
|
68 |
+
return quiz_html
|
69 |
+
|
70 |
+
# Default GET request handling
|
71 |
return """
|
72 |
<!DOCTYPE html>
|
73 |
<html lang="en">
|
|
|
78 |
</head>
|
79 |
<body>
|
80 |
<h2>Generate Quiz</h2>
|
81 |
+
<form action="/" method="post">
|
82 |
<label for="context">Context:</label><br>
|
83 |
<textarea id="context" name="context" rows="4" cols="50" required></textarea><br><br>
|
84 |
<input type="submit" value="Generate Quiz">
|
|
|
87 |
</html>
|
88 |
"""
|
89 |
|
90 |
+
if __name__ == "__main__":
|
91 |
+
app.run(debug=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|