Update app.py
Browse files
app.py
CHANGED
@@ -197,48 +197,72 @@ for answer in imp_keywords:
|
|
197 |
"""# **UI by using Gradio**"""
|
198 |
|
199 |
import gradio as gr
|
|
|
200 |
|
201 |
|
202 |
-
context = gr.Textbox(lines=10, placeholder="Enter paragraph/content here...", label="
|
203 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
204 |
-
subject = gr.Textbox(placeholder="Enter subject/title here...", label="
|
205 |
|
206 |
output = gr.Markdown( label="Question and Answers")
|
207 |
|
208 |
|
209 |
def generate_question_text(context,subject,total):
|
210 |
-
summary_text = summarizer(context,summary_model,summary_tokenizer)
|
211 |
-
for wrp in wrap(summary_text, 150):
|
212 |
-
print (wrp)
|
213 |
-
np = get_keywords(context,summary_text,total)
|
214 |
-
print ("\n\nNoun phrases",np)
|
215 |
-
output="<b style='color:black;'>Answer the following short questions.</b><br><br>"
|
216 |
-
i=1
|
217 |
-
for answer in np:
|
218 |
-
ques = get_question(summary_text,answer,question_model,question_tokenizer)
|
219 |
-
# output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
|
220 |
-
output = output + "<b style='color:black;'>Q"+ str(i) + ") " + ques + "</b><br>"
|
221 |
-
# output = output + "<br>"
|
222 |
-
output = output + "<br>"
|
223 |
-
i += 1
|
224 |
-
|
225 |
-
output = output + "<br><b style='color:black;'>" + "Correct Answer Key:</b><br>"
|
226 |
|
227 |
-
|
228 |
-
|
229 |
-
output = output + "<b style='color:green;'>" + "Ans"+ str(i) + ": " +answer.capitalize()+ "</b>"
|
230 |
-
output = output + "<br>"
|
231 |
-
i += 1
|
232 |
|
233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
234 |
|
235 |
iface = gr.Interface(
|
236 |
fn=generate_question_text,
|
237 |
inputs=[context,subject, total],
|
238 |
-
outputs=output,
|
239 |
-
allow_flagging="
|
240 |
|
241 |
-
# iface.launch(debug=True
|
242 |
|
243 |
def generate_question(context,subject,total):
|
244 |
summary_text = summarizer(context,summary_model,summary_tokenizer)
|
@@ -277,30 +301,53 @@ def filecreate(x,subject,total):
|
|
277 |
with open(x.name) as fo:
|
278 |
text = fo.read()
|
279 |
# print(text)
|
280 |
-
generated = generate_question(text,subject, total)
|
281 |
|
282 |
-
|
|
|
283 |
|
284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
|
286 |
import gradio as gr
|
287 |
|
288 |
context = gr.HTML(label="Text")
|
289 |
-
file = gr.File()
|
290 |
-
subject = gr.Textbox(placeholder="Enter subject/title here...", label="
|
291 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
292 |
|
293 |
|
294 |
-
# output = gr.HTML( label="Question and Answers")
|
295 |
-
|
296 |
fface = gr.Interface(
|
297 |
fn=filecreate,
|
298 |
inputs=[file,subject,total],
|
299 |
outputs=context,
|
300 |
-
|
|
|
301 |
|
302 |
|
303 |
# fface.launch(debug=True, share=True)
|
304 |
|
305 |
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"])
|
306 |
-
demo.launch(debug=True)
|
|
|
197 |
"""# **UI by using Gradio**"""
|
198 |
|
199 |
import gradio as gr
|
200 |
+
import re
|
201 |
|
202 |
|
203 |
+
context = gr.Textbox(lines=10, placeholder="Enter paragraph/content here...", label="Enter your content (words input must be more than 150 words).")
|
204 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
205 |
+
subject = gr.Textbox(placeholder="Enter subject/title here...", label="Enter your title (title must contain 1 word)")
|
206 |
|
207 |
output = gr.Markdown( label="Question and Answers")
|
208 |
|
209 |
|
210 |
def generate_question_text(context,subject,total):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
|
212 |
+
words_text = len(re.findall(r'\w+', context))
|
213 |
+
words_subject = len(re.findall(r'\w+', subject))
|
|
|
|
|
|
|
214 |
|
215 |
+
if (words_text < 150):
|
216 |
+
raise gr.Error("Invalid Input (Words limit must be more than 150 words).")
|
217 |
+
# print("Number of words:", words)
|
218 |
+
|
219 |
+
elif (words_subject < 1):
|
220 |
+
raise gr.Error("Invalid Input (Title must be one or more than one word).")
|
221 |
+
|
222 |
+
else:
|
223 |
+
summary_text = summarizer(context,summary_model,summary_tokenizer)
|
224 |
+
for wrp in wrap(summary_text, 150):
|
225 |
+
print (wrp)
|
226 |
+
np = get_keywords(context,summary_text,total)
|
227 |
+
print ("\n\nNoun phrases",np)
|
228 |
+
output="<b style='color:black;'>Answer the following short questions.</b><br><br>"
|
229 |
+
i=1
|
230 |
+
for answer in np:
|
231 |
+
ques = get_question(summary_text,answer,question_model,question_tokenizer)
|
232 |
+
# output= output + ques + "\n" + "Ans: "+answer.capitalize() + "\n\n"
|
233 |
+
output = output + "<b style='color:black;'>Q"+ str(i) + ") " + ques + "</b><br>"
|
234 |
+
# output = output + "<br>"
|
235 |
+
output = output + "<br>"
|
236 |
+
i += 1
|
237 |
+
|
238 |
+
output = output + "<br><b style='color:black;'>" + "Correct Answer Key:</b><br>"
|
239 |
+
|
240 |
+
i=1
|
241 |
+
for answer in np:
|
242 |
+
output = output + "<b style='color:green;'>" + "Ans"+ str(i) + ": " +answer.capitalize()+ "</b>"
|
243 |
+
output = output + "<br>"
|
244 |
+
i += 1
|
245 |
+
|
246 |
+
# mycursor = mydb.cursor()
|
247 |
+
# timedate = datetime.datetime.now()
|
248 |
+
|
249 |
+
# sql = "INSERT INTO shorttexts (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
250 |
+
# val = (subject, context, output, timedate)
|
251 |
+
# mycursor.execute(sql, val)
|
252 |
+
|
253 |
+
# mydb.commit()
|
254 |
+
|
255 |
+
# print(mycursor.rowcount, "record inserted.")
|
256 |
+
|
257 |
+
return output
|
258 |
|
259 |
iface = gr.Interface(
|
260 |
fn=generate_question_text,
|
261 |
inputs=[context,subject, total],
|
262 |
+
outputs=output,
|
263 |
+
allow_flagging="never",flagging_options=["Save Data"])
|
264 |
|
265 |
+
# iface.launch(debug=True)
|
266 |
|
267 |
def generate_question(context,subject,total):
|
268 |
summary_text = summarizer(context,summary_model,summary_tokenizer)
|
|
|
301 |
with open(x.name) as fo:
|
302 |
text = fo.read()
|
303 |
# print(text)
|
|
|
304 |
|
305 |
+
words_text = len(re.findall(r'\w+', text))
|
306 |
+
words_subject = len(re.findall(r'\w+', subject))
|
307 |
|
308 |
+
|
309 |
+
if (words_text < 150):
|
310 |
+
raise gr.Error("Invalid Input (Words limit must be more than 150 words).")
|
311 |
+
# print("Number of words:", words)
|
312 |
+
|
313 |
+
elif (words_subject < 1):
|
314 |
+
raise gr.Error("Invalid Input (Title must be one or more than one word).")
|
315 |
+
|
316 |
+
else:
|
317 |
+
|
318 |
+
generated = generate_question(text,subject, total)
|
319 |
+
|
320 |
+
# mycursor = mydb.cursor()
|
321 |
+
|
322 |
+
# timedate= datetime.datetime.now()
|
323 |
+
|
324 |
+
# sql = "INSERT INTO shortfiles (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
325 |
+
# val = (subject, text, generated, timedate)
|
326 |
+
# mycursor.execute(sql, val)
|
327 |
+
|
328 |
+
# mydb.commit()
|
329 |
+
|
330 |
+
# print(mycursor.rowcount, "record inserted.")
|
331 |
+
|
332 |
+
return generated
|
333 |
|
334 |
import gradio as gr
|
335 |
|
336 |
context = gr.HTML(label="Text")
|
337 |
+
file = gr.File(label="Upload your file (File must contain more than 150 words).")
|
338 |
+
subject = gr.Textbox(placeholder="Enter subject/title here...", label="Enter your title (title must contain 1 word).")
|
339 |
total = gr.Slider(1,10, value=1,step=1, label="Total Number Of Questions")
|
340 |
|
341 |
|
|
|
|
|
342 |
fface = gr.Interface(
|
343 |
fn=filecreate,
|
344 |
inputs=[file,subject,total],
|
345 |
outputs=context,
|
346 |
+
# css=".gradio-container {background-image: url('file=blue.jpg')}",
|
347 |
+
allow_flagging="never",flagging_options=["Save Data"])
|
348 |
|
349 |
|
350 |
# fface.launch(debug=True, share=True)
|
351 |
|
352 |
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"])
|
353 |
+
demo.launch(debug=True, show_api=False)
|