pragnakalp commited on
Commit
f4c86b6
1 Parent(s): 4fbea90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -35
app.py CHANGED
@@ -130,41 +130,38 @@ def get_location(ip_addr):
130
  print("response======>>",response)
131
  return response
132
 
133
- def generate_emotion(article):
134
- text = "Input sentence: "
135
- text += article
136
-
137
- model_ner = Ner(bert_ner_model)
138
-
139
- output = model_ner.predict(text)
140
- print(output)
141
- k = 0
142
- Entities_Found.clear()
143
- Entity_Types.clear()
144
- save_data_and_sendmail(article,output)
145
- for i in output:
146
- for j in i:
147
- if k == 0:
148
- Entities_Found.append(j)
149
- k += 1
150
- else:
151
- Entity_Types.append(j)
152
- k = 0
153
- result = {'Entities Found':Entities_Found, 'Entity Types':Entity_Types}
154
-
155
- return pd.DataFrame(result)
 
 
 
156
 
157
 
158
  def save_data_and_sendmail(article,output):
159
  try:
160
  print("welcome")
161
  ip_address = ''
162
- # ip_address = get_device_ip_address()
163
- # ip_address=str(request.remote_addr)
164
- # print(ip_address)
165
- # location = get_location(ip_address)
166
- # location = get_location(ip_address)
167
- # print(ip_address)
168
 
169
  ip_address= getIP()
170
  print(ip_address)
@@ -194,7 +191,7 @@ def save_data_and_sendmail(article,output):
194
  return "Error while sending mail" + str(e)
195
 
196
  input=gr.Textbox(lines=3, value=input_value, label="Input Text")
197
- output = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(2, "fixed"), headers=["Entities Found","Entity Types"], lable="Here is the result")]
198
  # with gr.Blocks(css=".gradio-container {background-color: lightgray}") as demo:
199
  # gr.Markdown("<h1 style='text-align: center;'>"+ "Named Entity Recognition Using BERT" + "</h1><br/><br/>")
200
  # with gr.Row():
@@ -215,14 +212,15 @@ output = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(2, "fixed"), heade
215
  # demo.launch()
216
 
217
  demo = gr.Interface(
218
- generate_emotion,
219
  input,
220
  output,
221
  title="Named Entity Recognition Using BERT",
222
  css=".gradio-container {background-color: lightgray} #inp_div {background-color: #7FB3D5;",
223
- article="""Feel free to give us your [feedback](https://www.pragnakalp.com/contact/) on this NER demo. For all your Named Entity Recognition related
224
- requirements, we are here to help you. Email us your requirement at [[email protected]]("mailto:[email protected]").
225
- And don't forget to check out more interesting [NLP services](https://www.pragnakalp.com/services/natural-language-processing-services/) we are offering.
226
- <p style='text-align: center;'>Developed by :[ Pragnakalp Techlabs](https://www.pragnakalp.com)</p>"""
 
227
  )
228
  demo.launch()
 
130
  print("response======>>",response)
131
  return response
132
 
133
+ def generate_ner(article):
134
+ result = {'Entities Found':[], 'Entity Types':[]}
135
+ if article.strip():
136
+ text = "Input sentence: "
137
+ text += article
138
+
139
+ model_ner = Ner(bert_ner_model)
140
+
141
+ output = model_ner.predict(text)
142
+ print(output)
143
+ k = 0
144
+ Entities_Found.clear()
145
+ Entity_Types.clear()
146
+ save_data_and_sendmail(article,output)
147
+ for i in output:
148
+ for j in i:
149
+ if k == 0:
150
+ Entities_Found.append(j)
151
+ k += 1
152
+ else:
153
+ Entity_Types.append(j)
154
+ k = 0
155
+ result = {'Entities Found':Entities_Found, 'Entity Types':Entity_Types}
156
+ return pd.DataFrame(result)
157
+ else:
158
+ raise gr.Error("Please enter text in inputbox!!!!")
159
 
160
 
161
  def save_data_and_sendmail(article,output):
162
  try:
163
  print("welcome")
164
  ip_address = ''
 
 
 
 
 
 
165
 
166
  ip_address= getIP()
167
  print(ip_address)
 
191
  return "Error while sending mail" + str(e)
192
 
193
  input=gr.Textbox(lines=3, value=input_value, label="Input Text")
194
+ output = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(2, "fixed"), headers=["Entities Found","Entity Types"], lable="Here is the result"),wrap=True]
195
  # with gr.Blocks(css=".gradio-container {background-color: lightgray}") as demo:
196
  # gr.Markdown("<h1 style='text-align: center;'>"+ "Named Entity Recognition Using BERT" + "</h1><br/><br/>")
197
  # with gr.Row():
 
212
  # demo.launch()
213
 
214
  demo = gr.Interface(
215
+ generate_ner,
216
  input,
217
  output,
218
  title="Named Entity Recognition Using BERT",
219
  css=".gradio-container {background-color: lightgray} #inp_div {background-color: #7FB3D5;",
220
+ article="""<p style='text-align: center;'>Feel free to give us your <a href="https://www.pragnakalp.com/contact/" target="_blank">feedback</a> on this NER demo.
221
+ For all your Named Entity Recognition related requirements, we are here to help you. Email us your requirement at
222
+ <a href="mailto:[email protected]" target="_blank">[email protected]</a>. And don't forget to check out more interesting
223
+ <a href="https://www.pragnakalp.com/services/natural-language-processing-services/" target="_blank">NLP services</a> we are offering.
224
+ <p style='text-align: center;'>Developed by :<a href="https://www.pragnakalp.com" target="_blank"> Pragnakalp Techlabs</a></p>"""
225
  )
226
  demo.launch()