Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -7,11 +7,11 @@ from openai import OpenAI
|
|
7 |
from huggingface_hub import login
|
8 |
from huggingface_hub import hf_hub_download
|
9 |
import logfire
|
|
|
10 |
|
11 |
|
12 |
logfire.configure(token=os.getenv("LOGFIRE_API_KEY"))
|
13 |
-
|
14 |
-
|
15 |
|
16 |
# Load your pre-trained model and label names
|
17 |
# model_path = hf_hub_download(repo_id="govtech/zoo-entry-001", filename="model.joblib", use_auth_token=True)
|
@@ -19,6 +19,16 @@ model_data = joblib.load("model.joblib")
|
|
19 |
model = model_data['model']
|
20 |
label_names = model_data['label_names']
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Initialize OpenAI client
|
23 |
client = OpenAI()
|
24 |
|
@@ -53,7 +63,15 @@ def classify_text(text):
|
|
53 |
'Prediction': (probabilities[0] > 0.5).astype(int)
|
54 |
})
|
55 |
# Return an update to the DataFrame component to make it visible with the results
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
return gr.update(value=df, visible=True)
|
58 |
|
59 |
with gr.Blocks(title="Zoo Entry 001") as iface:
|
|
|
7 |
from huggingface_hub import login
|
8 |
from huggingface_hub import hf_hub_download
|
9 |
import logfire
|
10 |
+
from pydantic import BaseModel
|
11 |
|
12 |
|
13 |
logfire.configure(token=os.getenv("LOGFIRE_API_KEY"))
|
14 |
+
logfire.instrument_pydantic()
|
|
|
15 |
|
16 |
# Load your pre-trained model and label names
|
17 |
# model_path = hf_hub_download(repo_id="govtech/zoo-entry-001", filename="model.joblib", use_auth_token=True)
|
|
|
19 |
model = model_data['model']
|
20 |
label_names = model_data['label_names']
|
21 |
|
22 |
+
class results(BaseModel):
|
23 |
+
text: str
|
24 |
+
hateful: float
|
25 |
+
insults: float
|
26 |
+
sexual: float
|
27 |
+
violence: float
|
28 |
+
self_harm: float
|
29 |
+
aom: float
|
30 |
+
|
31 |
+
|
32 |
# Initialize OpenAI client
|
33 |
client = OpenAI()
|
34 |
|
|
|
63 |
'Prediction': (probabilities[0] > 0.5).astype(int)
|
64 |
})
|
65 |
# Return an update to the DataFrame component to make it visible with the results
|
66 |
+
results(
|
67 |
+
text=text,
|
68 |
+
hateful=probabilities[0][0].round(4),
|
69 |
+
insults=probabilities[0][1].round(4),
|
70 |
+
sexual=probabilities[0][2].round(4),
|
71 |
+
violence=probabilities[0][3].round(4),
|
72 |
+
self_harm=probabilities[0][4].round(4),
|
73 |
+
aom=probabilities[0][5].round(4),
|
74 |
+
)
|
75 |
return gr.update(value=df, visible=True)
|
76 |
|
77 |
with gr.Blocks(title="Zoo Entry 001") as iface:
|