Spaces:
Runtime error
Runtime error
import gradio as gr | |
from openai import OpenAI | |
import os | |
from transformers import pipeline | |
# from dotenv import load_dotenv, find_dotenv | |
import huggingface_hub | |
# _ = load_dotenv(find_dotenv()) # read local .env file | |
hf_token= os.environ['HF_TOKEN'] | |
huggingface_hub.login(hf_token) | |
pipe = pipeline("token-classification", model="elshehawy/finer-ord-transformers", use_auth_token=True) | |
llm_model = 'gpt-3.5-turbo-0125' | |
# openai.api_key = os.environ['OPENAI_API_KEY'] | |
client = OpenAI( | |
api_key=os.environ.get("OPENAI_API_KEY"), | |
) | |
def get_completion(prompt, model=llm_model): | |
messages = [{"role": "user", "content": prompt}] | |
response = client.chat.completions.create( | |
messages=messages, | |
model=model, | |
temperature=0, | |
) | |
return response.choices[0].message.content | |
def find_orgs(sentence, choice): | |
prompt = f""" | |
In context of named entity recognition (NER), find all organizations in the text delimited by triple backticks. | |
text: | |
``` | |
{sentence} | |
``` | |
You should always start your answer with "Organizations are: " | |
""" | |
if choice=='GPT': | |
return get_completion(prompt) | |
else: | |
return pipe(sentence) | |
example = """ | |
My latest exclusive for The Hill : Conservative frustration over Republican efforts to force a House vote on reauthorizing the Export - Import Bank boiled over Wednesday during a contentious GOP meeting. | |
""" | |
radio_btn = gr.Radio(choices=['GPT', 'iSemantics'], value='iSemantics') | |
textbox = gr.Textbox(label="Enter your text", placeholder="", lines=4) | |
iface = gr.Interface(fn=find_orgs, inputs=[textbox, radio_btn], outputs="text", examples=[[example]]) | |
iface.launch(share=True) | |