Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,3 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""MatchingGenerator.ipynb
|
3 |
-
|
4 |
-
Automatically generated by Colaboratory.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/1drOrBUfaj_UMytwxar_keRWNm5ScaBi7
|
8 |
-
"""
|
9 |
|
10 |
from textwrap3 import wrap
|
11 |
|
@@ -40,9 +32,9 @@ def set_seed(seed: int):
|
|
40 |
set_seed(42)
|
41 |
|
42 |
import nltk
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
from nltk.corpus import wordnet as wn
|
47 |
from nltk.tokenize import sent_tokenize
|
48 |
|
@@ -201,15 +193,6 @@ def get_question(context,answer,model,tokenizer):
|
|
201 |
|
202 |
"""# **UI by using Gradio**"""
|
203 |
|
204 |
-
import mysql.connector
|
205 |
-
import datetime;
|
206 |
-
|
207 |
-
mydb = mysql.connector.connect(
|
208 |
-
host="qtechdb-1.cexugk1h8rui.ap-northeast-1.rds.amazonaws.com",
|
209 |
-
user="admin",
|
210 |
-
password="F3v2vGWzb8vaniE3nqzi",
|
211 |
-
database="spring_social"
|
212 |
-
)
|
213 |
|
214 |
import gradio as gr
|
215 |
import random
|
@@ -256,24 +239,14 @@ def generate_question_text(context,subject,total):
|
|
256 |
# random.shuffle(output)
|
257 |
output = output + "<br/>"
|
258 |
i += 1
|
259 |
-
|
260 |
-
mycursor = mydb.cursor()
|
261 |
-
timedate = datetime.datetime.now()
|
262 |
-
|
263 |
-
sql = "INSERT INTO matchtexts (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
264 |
-
val = (subject, context, output, timedate)
|
265 |
-
mycursor.execute(sql, val)
|
266 |
|
267 |
-
mydb.commit()
|
268 |
-
|
269 |
-
print(mycursor.rowcount, "record inserted.")
|
270 |
|
271 |
return output
|
272 |
|
273 |
iface = gr.Interface(
|
274 |
fn=generate_question_text,
|
275 |
inputs=[context,subject, total],
|
276 |
-
outputs=output,
|
277 |
allow_flagging="manual",flagging_options=["Save Data"])
|
278 |
|
279 |
# iface.launch(debug=True, share=True)
|
@@ -330,16 +303,6 @@ def filecreate(x,subject,total):
|
|
330 |
# print(text)
|
331 |
generated = generate_question(text,subject, total)
|
332 |
|
333 |
-
mycursor = mydb.cursor()
|
334 |
-
timedate= datetime.datetime.now()
|
335 |
-
|
336 |
-
sql = "INSERT INTO matchfiles (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
337 |
-
val = (subject, text, generated, timedate)
|
338 |
-
mycursor.execute(sql, val)
|
339 |
-
|
340 |
-
mydb.commit()
|
341 |
-
|
342 |
-
print(mycursor.rowcount, "record inserted.")
|
343 |
|
344 |
return generated
|
345 |
|
@@ -356,10 +319,9 @@ fface = gr.Interface(
|
|
356 |
fn=filecreate,
|
357 |
inputs=[file,subject,total],
|
358 |
outputs=context,
|
359 |
-
css=".gradio-container {background-image: url('file=blue.jpg')}",
|
360 |
allow_flagging="manual",flagging_options=["Save Data"])
|
361 |
|
362 |
# fface.launch(debug=True, share=True)
|
363 |
|
364 |
-
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"]
|
365 |
demo.launch(debug=True, share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
from textwrap3 import wrap
|
3 |
|
|
|
32 |
set_seed(42)
|
33 |
|
34 |
import nltk
|
35 |
+
nltk.download('punkt')
|
36 |
+
nltk.download('brown')
|
37 |
+
nltk.download('wordnet')
|
38 |
from nltk.corpus import wordnet as wn
|
39 |
from nltk.tokenize import sent_tokenize
|
40 |
|
|
|
193 |
|
194 |
"""# **UI by using Gradio**"""
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
import gradio as gr
|
198 |
import random
|
|
|
239 |
# random.shuffle(output)
|
240 |
output = output + "<br/>"
|
241 |
i += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
242 |
|
|
|
|
|
|
|
243 |
|
244 |
return output
|
245 |
|
246 |
iface = gr.Interface(
|
247 |
fn=generate_question_text,
|
248 |
inputs=[context,subject, total],
|
249 |
+
outputs=output,
|
250 |
allow_flagging="manual",flagging_options=["Save Data"])
|
251 |
|
252 |
# iface.launch(debug=True, share=True)
|
|
|
303 |
# print(text)
|
304 |
generated = generate_question(text,subject, total)
|
305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
|
307 |
return generated
|
308 |
|
|
|
319 |
fn=filecreate,
|
320 |
inputs=[file,subject,total],
|
321 |
outputs=context,
|
|
|
322 |
allow_flagging="manual",flagging_options=["Save Data"])
|
323 |
|
324 |
# fface.launch(debug=True, share=True)
|
325 |
|
326 |
+
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"])
|
327 |
demo.launch(debug=True, share=True)
|