Spaces:
Runtime error
Runtime error
set llm_model to "gpt-4-0125-preview"
Browse files
app.py
CHANGED
@@ -7,28 +7,18 @@ from transformers import pipeline
|
|
7 |
# from dotenv import load_dotenv, find_dotenv
|
8 |
import huggingface_hub
|
9 |
import json
|
10 |
-
# from simcse import SimCSE # use for gpt
|
11 |
from evaluate_data import store_sample_data, get_metrics_trf
|
12 |
from sentence_transformers import SentenceTransformer
|
13 |
from tqdm import tqdm
|
14 |
-
# store_sample_data()
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
# with open('./data/sample_data.json', 'r') as f:
|
19 |
-
# # sample_data = [
|
20 |
-
# # {'id': "", 'text': "", 'orgs': ["", ""]}
|
21 |
-
# # ]
|
22 |
-
# sample_data = json.load(f)
|
23 |
-
|
24 |
-
# _ = load_dotenv(find_dotenv()) # read local .env file
|
25 |
hf_token= os.environ['HF_TOKEN']
|
26 |
huggingface_hub.login(hf_token)
|
27 |
|
28 |
pipe = pipeline("token-classification", model="elshehawy/finer-ord-transformers", aggregation_strategy="first")
|
29 |
|
30 |
|
31 |
-
llm_model = 'gpt-3.5-turbo-0125'
|
|
|
32 |
# openai.api_key = os.environ['OPENAI_API_KEY']
|
33 |
|
34 |
client = OpenAI(
|
@@ -63,31 +53,6 @@ def find_orgs_gpt(sentence):
|
|
63 |
return sent_orgs
|
64 |
|
65 |
|
66 |
-
|
67 |
-
# def find_orgs_trf(sentence):
|
68 |
-
# org_list = []
|
69 |
-
# for ent in pipe(sentence):
|
70 |
-
# if ent['entity_group'] == 'ORG':
|
71 |
-
# # message += f'\n- {ent["word"]} \t- score: {ent["score"]}'
|
72 |
-
# # message += f'\n- {ent["word"]}'# \t- score: {ent["score"]}'
|
73 |
-
# org_list.append(ent['word'])
|
74 |
-
# return list(set(org_list))
|
75 |
-
|
76 |
-
|
77 |
-
# true_orgs = [sent['orgs'] for sent in sample_data]
|
78 |
-
|
79 |
-
# predicted_orgs_gpt = [find_orgs_gpt(sent['text']) for sent in sample_data]
|
80 |
-
# predicted_orgs_trf = [find_orgs_trf(sent['text']) for sent in sample_data]
|
81 |
-
|
82 |
-
# all_metrics = {}
|
83 |
-
|
84 |
-
# sim_model = SimCSE('sentence-transformers/all-MiniLM-L6-v2')
|
85 |
-
# all_metrics['gpt'] = calc_metrics(true_orgs, predicted_orgs_gpt, sim_model)
|
86 |
-
# print('Finiding all metrics trf')
|
87 |
-
# all_metrics['trf'] = get_metrics_trf()
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
example = """
|
92 |
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.
|
93 |
|
@@ -111,18 +76,11 @@ def find_orgs(uploaded_file):
|
|
111 |
all_metrics['trf'] = get_metrics_trf(uploaded_data)
|
112 |
|
113 |
|
114 |
-
# with open('./data/sample_data.json', 'r') as f:
|
115 |
-
# sample_data = json.load(f)
|
116 |
|
117 |
|
118 |
-
|
119 |
-
|
120 |
-
# sim_model = SimCSE('sentence-transformers/all-MiniLM-L6-v2')
|
121 |
-
|
122 |
print(all_metrics)
|
123 |
return all_metrics
|
124 |
-
|
125 |
-
# textbox = gr.Textbox(label="Enter your text", placeholder=str(all_metrics), lines=8)
|
126 |
upload_btn = gr.UploadButton(label='Upload a json file.', type='binary')
|
127 |
|
128 |
iface = gr.Interface(fn=find_orgs, inputs=upload_btn, outputs="text")
|
|
|
7 |
# from dotenv import load_dotenv, find_dotenv
|
8 |
import huggingface_hub
|
9 |
import json
|
|
|
10 |
from evaluate_data import store_sample_data, get_metrics_trf
|
11 |
from sentence_transformers import SentenceTransformer
|
12 |
from tqdm import tqdm
|
|
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
hf_token= os.environ['HF_TOKEN']
|
15 |
huggingface_hub.login(hf_token)
|
16 |
|
17 |
pipe = pipeline("token-classification", model="elshehawy/finer-ord-transformers", aggregation_strategy="first")
|
18 |
|
19 |
|
20 |
+
# llm_model = 'gpt-3.5-turbo-0125'
|
21 |
+
llm_model = 'gpt-4-0125-preview'
|
22 |
# openai.api_key = os.environ['OPENAI_API_KEY']
|
23 |
|
24 |
client = OpenAI(
|
|
|
53 |
return sent_orgs
|
54 |
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
example = """
|
57 |
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.
|
58 |
|
|
|
76 |
all_metrics['trf'] = get_metrics_trf(uploaded_data)
|
77 |
|
78 |
|
|
|
|
|
79 |
|
80 |
|
|
|
|
|
|
|
|
|
81 |
print(all_metrics)
|
82 |
return all_metrics
|
83 |
+
|
|
|
84 |
upload_btn = gr.UploadButton(label='Upload a json file.', type='binary')
|
85 |
|
86 |
iface = gr.Interface(fn=find_orgs, inputs=upload_btn, outputs="text")
|