Update app.py
Browse files
app.py
CHANGED
@@ -176,45 +176,69 @@ def get_question(context,answer,model,tokenizer):
|
|
176 |
|
177 |
|
178 |
import gradio as gr
|
|
|
179 |
|
180 |
-
context = gr.Textbox(lines=10, placeholder="Enter paragraph/content here...", label="
|
181 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
182 |
-
subject = gr.Textbox(placeholder="Enter subject/title here...", label="
|
183 |
|
184 |
|
185 |
output = gr.Markdown( label="Question and Answers")
|
186 |
|
187 |
|
188 |
def generate_question_text(context,subject,total):
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
output =
|
206 |
-
|
207 |
-
|
208 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
iface = gr.Interface(
|
211 |
fn=generate_question_text,
|
212 |
inputs=[context,subject, total],
|
213 |
outputs=output,
|
214 |
-
|
|
|
215 |
|
216 |
# iface.launch(debug=True, share=True)
|
217 |
|
|
|
218 |
def generate_question(context,subject,total):
|
219 |
summary_text = summarizer(context,summary_model,summary_tokenizer)
|
220 |
for wrp in wrap(summary_text, 150):
|
@@ -248,26 +272,51 @@ def filecreate(x,subject,total):
|
|
248 |
with open(x.name) as fo:
|
249 |
text = fo.read()
|
250 |
# print(text)
|
251 |
-
generated = generate_question(text,subject, total)
|
252 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
-
|
255 |
-
|
256 |
|
257 |
import gradio as gr
|
258 |
|
259 |
context = gr.HTML(label="Text")
|
260 |
-
file = gr.File()
|
261 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
262 |
-
subject = gr.Textbox(placeholder="Enter subject/title here...", label="
|
263 |
|
264 |
fface = gr.Interface(
|
265 |
fn=filecreate,
|
266 |
inputs=[file,subject,total],
|
267 |
outputs=context,
|
268 |
-
|
|
|
269 |
|
270 |
# fface.launch(debug=True, share=True)
|
271 |
|
272 |
-
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"]
|
273 |
-
demo.launch(debug=True)
|
|
|
176 |
|
177 |
|
178 |
import gradio as gr
|
179 |
+
import re
|
180 |
|
181 |
+
context = gr.Textbox(lines=10, placeholder="Enter paragraph/content here...", label="Enter your content (words input must be more than 150 words).")
|
182 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
183 |
+
subject = gr.Textbox(placeholder="Enter subject/title here...", label="Enter your title (title must contain 1 word)")
|
184 |
|
185 |
|
186 |
output = gr.Markdown( label="Question and Answers")
|
187 |
|
188 |
|
189 |
def generate_question_text(context,subject,total):
|
190 |
+
words_text = len(re.findall(r'\w+', context))
|
191 |
+
words_subject = len(re.findall(r'\w+', subject))
|
192 |
+
|
193 |
+
if (words_text < 150):
|
194 |
+
raise gr.Error("Invalid Input (Words limit must be more than 150 words).")
|
195 |
+
# print("Number of words:", words)
|
196 |
+
|
197 |
+
elif (words_subject < 1):
|
198 |
+
raise gr.Error("Invalid Input (Title must be one or more than one word).")
|
199 |
+
|
200 |
+
else:
|
201 |
+
summary_text = summarizer(context,summary_model,summary_tokenizer)
|
202 |
+
for wrp in wrap(summary_text, 150):
|
203 |
+
print (wrp)
|
204 |
+
np = get_keywords(context,summary_text,total)
|
205 |
+
print ("\n\nNoun phrases",np)
|
206 |
+
output="<b style='color:black;'>Answer the following true/false questions. Select the correct answer.</b><br><br>"
|
207 |
+
|
208 |
+
i=1
|
209 |
+
for answer in np:
|
210 |
+
ques = get_question(summary_text,answer,question_model,question_tokenizer)
|
211 |
+
# output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
|
212 |
+
output = output + "<b style='color:black;'>Q"+ str(i) + ") " + ques + "</b> <br>"
|
213 |
+
# output = output + "<br>"
|
214 |
+
output = output + "<b>" + "a) True <br></b>"
|
215 |
+
output = output + "<b>" + "b) False </b>"
|
216 |
+
|
217 |
+
output = output + "<br>"
|
218 |
+
i += 1
|
219 |
+
|
220 |
+
# mycursor = mydb.cursor()
|
221 |
+
# timedate = datetime.datetime.now()
|
222 |
+
|
223 |
+
# sql = "INSERT INTO truetexts (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
224 |
+
# val = (subject, context, output, timedate)
|
225 |
+
# mycursor.execute(sql, val)
|
226 |
+
|
227 |
+
# mydb.commit()
|
228 |
+
# print(mycursor.rowcount, "record inserted.")
|
229 |
+
|
230 |
+
return output
|
231 |
|
232 |
iface = gr.Interface(
|
233 |
fn=generate_question_text,
|
234 |
inputs=[context,subject, total],
|
235 |
outputs=output,
|
236 |
+
# css=".gradio-container {background-image: url('file=blue.jpg')}",
|
237 |
+
allow_flagging="never",flagging_options=["Save Data"])
|
238 |
|
239 |
# iface.launch(debug=True, share=True)
|
240 |
|
241 |
+
|
242 |
def generate_question(context,subject,total):
|
243 |
summary_text = summarizer(context,summary_model,summary_tokenizer)
|
244 |
for wrp in wrap(summary_text, 150):
|
|
|
272 |
with open(x.name) as fo:
|
273 |
text = fo.read()
|
274 |
# print(text)
|
|
|
275 |
|
276 |
+
words_text = len(re.findall(r'\w+', text))
|
277 |
+
words_subject = len(re.findall(r'\w+', subject))
|
278 |
+
|
279 |
+
|
280 |
+
if (words_text < 150):
|
281 |
+
raise gr.Error("Invalid Input (Words limit must be more than 150 words).")
|
282 |
+
# print("Number of words:", words)
|
283 |
+
|
284 |
+
elif (words_subject < 1):
|
285 |
+
raise gr.Error("Invalid Input (Title must be one or more than one word).")
|
286 |
+
|
287 |
+
else:
|
288 |
+
generated = generate_question(text,subject, total)
|
289 |
+
|
290 |
+
# mycursor = mydb.cursor()
|
291 |
+
|
292 |
+
# timedate= datetime.datetime.now()
|
293 |
+
|
294 |
+
# sql = "INSERT INTO truefiles (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
295 |
+
# val = (subject, text, generated, timedate)
|
296 |
+
# mycursor.execute(sql, val)
|
297 |
+
|
298 |
+
# mydb.commit()
|
299 |
+
|
300 |
+
# print(mycursor.rowcount, "record inserted.")
|
301 |
|
302 |
+
# return text
|
303 |
+
return generated
|
304 |
|
305 |
import gradio as gr
|
306 |
|
307 |
context = gr.HTML(label="Text")
|
308 |
+
file = gr.File(label="Upload your file (File must contain more than 150 words).")
|
309 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
310 |
+
subject = gr.Textbox(placeholder="Enter subject/title here...", label="Enter your title (title must contain 1 word).")
|
311 |
|
312 |
fface = gr.Interface(
|
313 |
fn=filecreate,
|
314 |
inputs=[file,subject,total],
|
315 |
outputs=context,
|
316 |
+
# css=".gradio-container {background-image: url('file=blue.jpg')}",
|
317 |
+
allow_flagging="never",flagging_options=["Save Data"])
|
318 |
|
319 |
# fface.launch(debug=True, share=True)
|
320 |
|
321 |
+
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"])
|
322 |
+
demo.launch(debug=True, show_api=False)
|