Spaces:
Running
Running
File size: 1,534 Bytes
3e0cc3d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
import gradio as gr
from datetime import date
import json
import csv
import datetime
import smtplib
from email.mime.text import MIMEText
import requests
from transformers import AutoTokenizer, AutoModelWithLMHead
import gc
import os
import json
import numpy as np
from tqdm import trange
import torch
import torch.nn.functional as F
from bert_ner_model_loader import Ner
import pandas as pd
cwd = os.getcwd()
bert_ner_model = os.path.join(cwd)
Entities_Found =[]
Entity_Types = []
k = 0
def generate_emotion(article):
text = "Input sentence: "
text += article
model_ner = Ner(bert_ner_model)
output = model_ner.predict(text)
print(output)
k = 0
for i in output:
for j in i:
if k == 0:
Entities_Found.append(j)
k += 1
else:
Entity_Types.append(j)
k = 0
result = {'Entities Found':Entities_Found, 'Entity Types':Entity_Types}
return pd.DataFrame(result)
inputs=gr.Textbox(lines=10, label="Sentences",elem_id="inp_div")
outputs = [gr.Dataframe(row_count = (2, "dynamic"), col_count=(2, "fixed"), label="Here is the Result", headers=["Entities Found","Entity Types"])]
demo = gr.Interface(
generate_emotion,
inputs,
outputs,
title="Entity Recognition For Input Text",
description="Feel free to give your feedback",
css=".gradio-container {background-color: lightgray} #inp_div {background-color: [#7](https://www1.example.com/issues/7)FB3D5;"
)
demo.launch() |