Technozam commited on
Commit
7374b4d
·
1 Parent(s): dcdf5f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -21
app.py CHANGED
@@ -90,28 +90,53 @@ print ("\n")
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")
95
- subject = gr.Textbox(placeholder="Enter subject/title here...", label="Text")
 
96
  output = gr.Markdown( label="Notes")
97
 
98
  def generate_question_text(context,subject):
99
- summary_text = summarizer(context,summary_model,summary_tokenizer)
100
- for wrp in wrap(summary_text, 150):
101
- print (wrp)
102
- # np = get_keywords(context,summary_text,total)
103
- # print ("\n\nNoun phrases",np)
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
- outputs=[output],
114
- allow_flagging="manual",flagging_options=["Save Data"])
115
 
116
  # iface.launch(debug=True, share=True)
117
 
@@ -139,27 +164,52 @@ def filecreate(x,subjectfile):
139
  with open(x.name) as fo:
140
  text = fo.read()
141
  # print(text)
142
- generated = generate_question(text,subject)
143
 
144
- return generated
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
145
 
146
  # filecreate(file)
147
 
148
  import gradio as gr
149
 
150
  context = gr.HTML(label="Text")
151
- subjectfile = gr.Textbox(placeholder="Enter subject/title here...", label="Text")
152
 
153
- file = gr.File()
154
 
155
  fface = gr.Interface(
156
  fn=filecreate,
157
  inputs=[file,subjectfile],
158
  outputs=context,
159
- allow_flagging="manual",flagging_options=["Save Data"])
160
-
161
 
162
  # fface.launch(debug=True, share=True)
163
 
164
  demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"])
165
- demo.launch(debug=True)
 
90
  """# **UI by using Gradio**"""
91
 
92
  import gradio as gr
93
+ import re
94
 
95
+
96
+ context = gr.Textbox(lines=10, placeholder="Enter paragraph/content here...", label="Enter your content (words input must be more than 150 words).")
97
+ subject = gr.Textbox(placeholder="Enter subject/title here...", label="Enter your title (title must contain 1 word)")
98
  output = gr.Markdown( label="Notes")
99
 
100
  def generate_question_text(context,subject):
 
 
 
 
 
 
 
 
101
 
102
+ words_text = len(re.findall(r'\w+', context))
103
+ words_subject = len(re.findall(r'\w+', subject))
104
+
105
+ if (words_text < 150):
106
+ raise gr.Error("Invalid Input (Words limit must be more than 150 words).")
107
+ # print("Number of words:", words)
108
+
109
+ elif (words_subject < 1):
110
+ raise gr.Error("Invalid Input (Title must be one or more than one word).")
111
+
112
+ else:
113
+ summary_text = summarizer(context,summary_model,summary_tokenizer)
114
+ for wrp in wrap(summary_text, 150):
115
+ print (wrp)
116
+ # np = get_keywords(context,summary_text,total)
117
+ # print ("\n\nNoun phrases",np)
118
+ output="<b style='color:black;'>Notes and key points of the topic are:</b><br>"
119
+ summary = summary_text
120
+ output = output+ summary
121
+
122
+ # mycursor = mydb.cursor()
123
+ # timedate = datetime.datetime.now()
124
+
125
+ # sql = "INSERT INTO notestexts (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
126
+ # val = (subject, context, output, timedate)
127
+ # mycursor.execute(sql, val)
128
+
129
+ # mydb.commit()
130
+
131
+ # print(mycursor.rowcount, "record inserted.")
132
+
133
+ return output
134
 
135
  iface = gr.Interface(
136
  fn=generate_question_text,
137
+ inputs=[context,subject], outputs=[output],
138
+ # css=".gradio-container {background-image: url('file=blue.jpg')}",
139
+ allow_flagging="never",flagging_options=["Save Data"])
140
 
141
  # iface.launch(debug=True, share=True)
142
 
 
164
  with open(x.name) as fo:
165
  text = fo.read()
166
  # print(text)
 
167
 
168
+ words_text = len(re.findall(r'\w+', text))
169
+ words_subject = len(re.findall(r'\w+', subjectfile))
170
+
171
+
172
+ if (words_text < 150):
173
+ raise gr.Error("Invalid Input (Words limit must be more than 150 words).")
174
+ # print("Number of words:", words)
175
+
176
+ elif (words_subject < 1):
177
+ raise gr.Error("Invalid Input (Title must be one or more than one word).")
178
+
179
+ else:
180
+ generated = generate_question(text,subject)
181
+
182
+ # mycursor = mydb.cursor()
183
+
184
+ # timedate= datetime.datetime.now()
185
+
186
+ # sql = "INSERT INTO notesfiles (subject, input, output, timedate) VALUES (%s,%s, %s,%s)"
187
+ # val = (subject, text, generated, timedate)
188
+ # mycursor.execute(sql, val)
189
+
190
+ # mydb.commit()
191
+
192
+ # print(mycursor.rowcount, "record inserted.")
193
+ # return text
194
+ return generated
195
 
196
  # filecreate(file)
197
 
198
  import gradio as gr
199
 
200
  context = gr.HTML(label="Text")
201
+ subjectfile = gr.Textbox(placeholder="Enter subject/title here...", label="Enter your title (title must contain 1 word).")
202
 
203
+ file = gr.File(label="Upload your file (File must contain more than 150 words).")
204
 
205
  fface = gr.Interface(
206
  fn=filecreate,
207
  inputs=[file,subjectfile],
208
  outputs=context,
209
+ # css=".gradio-container {background-image: url('file=blue.jpg')}",
210
+ allow_flagging="never",flagging_options=["Save Data"])
211
 
212
  # fface.launch(debug=True, share=True)
213
 
214
  demo = gr.TabbedInterface([iface, fface], ["Text", "Upload File"])
215
+ demo.launch(debug=True, show_api=False)