Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,3 @@
|
|
1 |
-
# -*- coding: utf-8 -*-
|
2 |
-
"""NotesGenerator.ipynb
|
3 |
-
|
4 |
-
Automatically generated by Colaboratory.
|
5 |
-
|
6 |
-
Original file is located at
|
7 |
-
https://colab.research.google.com/drive/1eq-p4wE1YK7TJ6TtBIV8BJr8SnfKzYdB
|
8 |
-
"""
|
9 |
|
10 |
from textwrap3 import wrap
|
11 |
|
@@ -41,9 +33,9 @@ def set_seed(seed: int):
|
|
41 |
set_seed(42)
|
42 |
|
43 |
import nltk
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
from nltk.corpus import wordnet as wn
|
48 |
from nltk.tokenize import sent_tokenize
|
49 |
|
@@ -97,16 +89,6 @@ print ("\n")
|
|
97 |
|
98 |
"""# **UI by using Gradio**"""
|
99 |
|
100 |
-
import mysql.connector
|
101 |
-
import datetime;
|
102 |
-
|
103 |
-
mydb = mysql.connector.connect(
|
104 |
-
host="qtechdb-1.cexugk1h8rui.ap-northeast-1.rds.amazonaws.com",
|
105 |
-
user="admin",
|
106 |
-
password="F3v2vGWzb8vaniE3nqzi",
|
107 |
-
database="spring_social"
|
108 |
-
)
|
109 |
-
|
110 |
import gradio as gr
|
111 |
|
112 |
context = gr.Textbox(lines=10, placeholder="Enter paragraph/content here...", label="Text")
|
@@ -122,24 +104,12 @@ def generate_question_text(context,subject):
|
|
122 |
output="<b style='color:black;'>Notes and key points of the topic are:</b><br>"
|
123 |
summary = summary_text
|
124 |
output = output+ summary
|
125 |
-
|
126 |
-
mycursor = mydb.cursor()
|
127 |
-
timedate = datetime.datetime.now()
|
128 |
-
|
129 |
-
sql = "INSERT INTO notestexts (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
130 |
-
val = (subject, context, output, timedate)
|
131 |
-
mycursor.execute(sql, val)
|
132 |
-
|
133 |
-
mydb.commit()
|
134 |
-
|
135 |
-
print(mycursor.rowcount, "record inserted.")
|
136 |
|
137 |
return output
|
138 |
|
139 |
iface = gr.Interface(
|
140 |
fn=generate_question_text,
|
141 |
inputs=[context,subject],
|
142 |
-
outputs=[output], css=".gradio-container {background-image: url('file=blue.jpg')}",
|
143 |
allow_flagging="manual",flagging_options=["Save Data"])
|
144 |
|
145 |
iface.launch(debug=True, share=True)
|
@@ -170,18 +140,6 @@ def filecreate(x,subjectfile):
|
|
170 |
# print(text)
|
171 |
generated = generate_question(text,subject)
|
172 |
|
173 |
-
mycursor = mydb.cursor()
|
174 |
-
|
175 |
-
timedate= datetime.datetime.now()
|
176 |
-
|
177 |
-
sql = "INSERT INTO notesfiles (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
|
178 |
-
val = (subject, text, generated, timedate)
|
179 |
-
mycursor.execute(sql, val)
|
180 |
-
|
181 |
-
mydb.commit()
|
182 |
-
|
183 |
-
print(mycursor.rowcount, "record inserted.")
|
184 |
-
# return text
|
185 |
return generated
|
186 |
|
187 |
# filecreate(file)
|
@@ -197,11 +155,10 @@ fface = gr.Interface(
|
|
197 |
fn=filecreate,
|
198 |
inputs=[file,subjectfile],
|
199 |
outputs=context,
|
200 |
-
css=".gradio-container {background-image: url('file=blue.jpg')}",
|
201 |
allow_flagging="manual",flagging_options=["Save Data"])
|
202 |
|
203 |
|
204 |
# fface.launch(debug=True, share=True)
|
205 |
|
206 |
-
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"]
|
207 |
demo.launch(debug=True, share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
|
2 |
from textwrap3 import wrap
|
3 |
|
|
|
33 |
set_seed(42)
|
34 |
|
35 |
import nltk
|
36 |
+
nltk.download('punkt')
|
37 |
+
nltk.download('brown')
|
38 |
+
nltk.download('wordnet')
|
39 |
from nltk.corpus import wordnet as wn
|
40 |
from nltk.tokenize import sent_tokenize
|
41 |
|
|
|
89 |
|
90 |
"""# **UI by using Gradio**"""
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
import gradio as gr
|
93 |
|
94 |
context = gr.Textbox(lines=10, placeholder="Enter paragraph/content here...", label="Text")
|
|
|
104 |
output="<b style='color:black;'>Notes and key points of the topic are:</b><br>"
|
105 |
summary = summary_text
|
106 |
output = output+ summary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
|
108 |
return output
|
109 |
|
110 |
iface = gr.Interface(
|
111 |
fn=generate_question_text,
|
112 |
inputs=[context,subject],
|
|
|
113 |
allow_flagging="manual",flagging_options=["Save Data"])
|
114 |
|
115 |
iface.launch(debug=True, share=True)
|
|
|
140 |
# print(text)
|
141 |
generated = generate_question(text,subject)
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
return generated
|
144 |
|
145 |
# filecreate(file)
|
|
|
155 |
fn=filecreate,
|
156 |
inputs=[file,subjectfile],
|
157 |
outputs=context,
|
|
|
158 |
allow_flagging="manual",flagging_options=["Save Data"])
|
159 |
|
160 |
|
161 |
# fface.launch(debug=True, share=True)
|
162 |
|
163 |
+
demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"])
|
164 |
demo.launch(debug=True, share=True)
|