Spaces:
Sleeping
Sleeping
RamiIbrahim
commited on
Commit
•
60e6eca
1
Parent(s):
64b1a12
5:11
Browse files
app.py
CHANGED
@@ -1,39 +1,26 @@
|
|
1 |
-
import os
|
2 |
-
import joblib
|
3 |
import gradio as gr
|
4 |
-
from
|
5 |
-
from sklearn.linear_model import LogisticRegression
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
9 |
|
10 |
-
def
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
return
|
16 |
|
17 |
-
|
18 |
-
model, vectorizer = load_model()
|
19 |
-
if model and vectorizer:
|
20 |
-
prediction = model.predict(input_vector)[0]
|
21 |
-
probabilities = model.predict_proba(input_vector)[0]
|
22 |
-
|
23 |
-
sentiment = "Positive" if prediction == 1 else "Negative"
|
24 |
-
confidence = probabilities[1] if prediction == 1 else probabilities[0]
|
25 |
-
|
26 |
-
return f"Sentiment: {sentiment}\nConfidence: {confidence:.4f}"
|
27 |
-
else:
|
28 |
-
return "Model not found or could not be loaded."
|
29 |
-
|
30 |
-
# Gradio Interface
|
31 |
iface = gr.Interface(
|
32 |
-
fn=
|
33 |
-
inputs="text",
|
34 |
-
outputs="
|
35 |
-
title="
|
36 |
-
description="Enter
|
37 |
)
|
38 |
|
|
|
39 |
iface.launch()
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
|
|
3 |
|
4 |
+
# Load your model and tokenizer
|
5 |
+
model_name = "your-model-name"
|
6 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
|
9 |
+
def predict(input_text):
|
10 |
+
# Tokenize and make prediction
|
11 |
+
inputs = tokenizer(input_text, return_tensors="pt", truncation=True, padding=True)
|
12 |
+
outputs = model(**inputs)
|
13 |
+
prediction = outputs.logits.argmax(-1).item()
|
14 |
+
return prediction
|
15 |
|
16 |
+
# Define Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
iface = gr.Interface(
|
18 |
+
fn=predict,
|
19 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
20 |
+
outputs="label",
|
21 |
+
title="Your Model Name",
|
22 |
+
description="Enter some text to get a prediction."
|
23 |
)
|
24 |
|
25 |
+
# Launch the interface
|
26 |
iface.launch()
|