Spaces:
Running
Running
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() |