mou3az commited on
Commit
bb9e9c5
1 Parent(s): 702b6bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +155 -4
app.py CHANGED
@@ -1,9 +1,10 @@
1
- from flask import Flask, request, jsonify, render_template
2
  from huggingface_hub import InferenceClient
3
  from requests.exceptions import RequestException
4
 
5
  app = Flask(__name__)
6
 
 
7
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
8
 
9
  def system_instructions(context):
@@ -61,10 +62,160 @@ def generate_quiz_page():
61
 
62
  if request.content_type == 'application/json':
63
  return jsonify(response)
64
-
65
- return render_template('quiz.html', textWithAnswers=response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
- return render_template('index.html')
68
 
69
  if __name__ == "__main__":
70
  app.run(debug=True)
 
1
+ from flask import Flask, request, jsonify
2
  from huggingface_hub import InferenceClient
3
  from requests.exceptions import RequestException
4
 
5
  app = Flask(__name__)
6
 
7
+
8
  client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2")
9
 
10
  def system_instructions(context):
 
62
 
63
  if request.content_type == 'application/json':
64
  return jsonify(response)
65
+
66
+
67
+ quiz_html = f"""
68
+ <!DOCTYPE html>
69
+ <html lang="en">
70
+ <head>
71
+ <meta charset="UTF-8">
72
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
73
+ <title>Generated Quiz</title>
74
+ <style>
75
+ body {{
76
+ font-family: Arial, sans-serif;
77
+ background-color: #f0f0f0; /* Light grey background */
78
+ color: #333; /* Dark grey text color */
79
+ margin: 20px;
80
+ }}
81
+ h2 {{
82
+ background-color: #ffc107; /* Yellow background for heading */
83
+ padding: 10px;
84
+ border-radius: 5px;
85
+ }}
86
+ form {{
87
+ display: none; /* Hide the form after generating quiz */
88
+ }}
89
+ .quiz-container {{
90
+ background-color: #f0f0f0; /* Light grey background */
91
+ padding: 20px;
92
+ border-radius: 5px;
93
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Light shadow effect */
94
+ margin-bottom: 20px;
95
+ }}
96
+ .quiz-container pre {{
97
+ white-space: pre-wrap; /* Preserve line breaks in quiz response */
98
+ }}
99
+ .generate-link {{
100
+ display: inline-block; /* Make the link inline-block */
101
+ margin-top: 10px;
102
+ border: 2px solid transparent; /* Transparent border initially */
103
+ padding: 5px 10px; /* Padding for spacing inside the border */
104
+ text-decoration: none; /* Remove underline */
105
+ color: #ffc107; /* Yellow text color */
106
+ font-weight: bold; /* Bold text */
107
+ border-radius: 4px;
108
+ background-color: #333; /* Dark grey background color */
109
+ }}
110
+ .generate-link:hover {{
111
+ text-decoration: none; /* Remove underline on hover */
112
+ background-color: #555; /* Darker grey background color on hover */
113
+ }}
114
+ a {{
115
+ color: #ffc107; /* Yellow text color for links */
116
+ text-decoration: none;
117
+ }}
118
+ a:hover {{
119
+ text-decoration: underline; /* Underline on hover */
120
+ }}
121
+ textarea {{
122
+ width: 100%;
123
+ padding: 10px;
124
+ border: 1px solid #ccc;
125
+ border-radius: 4px;
126
+ resize: vertical; /* Allow vertical resizing of textarea */
127
+ min-height: 150px; /* Minimum height for textarea */
128
+ }}
129
+ input[type="submit"] {{
130
+ background-color: #ffc107; /* Yellow background for submit button */
131
+ color: #333; /* Dark grey text color */
132
+ border: none;
133
+ padding: 10px 20px;
134
+ cursor: pointer;
135
+ border-radius: 4px;
136
+ }}
137
+ input[type="submit"]:hover {{
138
+ background-color: #ffca28; /* Lighter yellow on hover */
139
+ }}
140
+ </style>
141
+ </head>
142
+ <body>
143
+ <div class="quiz-container">
144
+ <h2>Generated Quiz</h2>
145
+ <pre>{response}</pre>
146
+ <a href="/" class="generate-link">Back to generate another quiz</a>
147
+ </div>
148
+ </body>
149
+ </html>
150
+ """
151
+
152
+ return quiz_html
153
+
154
+ # Default GET request handling
155
+ default_html = """
156
+ <!DOCTYPE html>
157
+ <html lang="en">
158
+ <head>
159
+ <meta charset="UTF-8">
160
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
161
+ <title>Generate Quiz</title>
162
+ <style>
163
+ body {
164
+ font-family: Arial, sans-serif;
165
+ background-color: #f0f0f0; /* Light grey background */
166
+ color: #333; /* Dark grey text color */
167
+ margin: 20px;
168
+ }
169
+ h2 {
170
+ background-color: #ffc107; /* Yellow background for heading */
171
+ padding: 10px;
172
+ border-radius: 5px;
173
+ }
174
+ form {
175
+ background-color: #fff; /* White background for form */
176
+ padding: 20px;
177
+ border-radius: 5px;
178
+ box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Light shadow effect */
179
+ margin-bottom: 20px;
180
+ }
181
+ label {
182
+ display: block;
183
+ margin-bottom: 10px;
184
+ }
185
+ textarea {
186
+ width: 98%;
187
+ padding: 10px;
188
+ border: 2px solid #ffc107; /* Yellow border */
189
+ border-radius: 4px;
190
+ resize: vertical; /* Allow vertical resizing of textarea */
191
+ min-height: 150px; /* Minimum height for textarea */
192
+ background-color: #f0f0f0; /* Light grey background */
193
+ }
194
+ input[type="submit"] {
195
+ background-color: #ffc107; /* Yellow background for submit button */
196
+ color: #333; /* Dark grey text color */
197
+ border: none;
198
+ padding: 10px 20px;
199
+ cursor: pointer;
200
+ border-radius: 4px;
201
+ }
202
+ input[type="submit"]:hover {
203
+ background-color: #ffca28; /* Lighter yellow on hover */
204
+ }
205
+ </style>
206
+ </head>
207
+ <body>
208
+ <h2>Generate Quiz</h2>
209
+ <form action="/" method="post">
210
+ <label for="context">Context:</label><br>
211
+ <textarea id="context" name="context" rows="20" required></textarea><br><br>
212
+ <input type="submit" value="Generate Quiz">
213
+ </form>
214
+ </body>
215
+ </html>
216
+ """
217
 
218
+ return default_html
219
 
220
  if __name__ == "__main__":
221
  app.run(debug=True)