File size: 1,680 Bytes
459de8c cd27398 7f83032 cd27398 aa93c53 7f83032 cd27398 7f83032 6f14908 7f83032 cd27398 459de8c 6f14908 7f83032 459de8c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import gradio as gr
from inference import SentimentClassifier
from huggingface_hub import snapshot_download
from huggingface_hub import hf_hub_download
import os
MODEL_REPO = "vuminhtue/qwen3_sentiment_tinystories"
FILENAME = "Qwen3_200k_model_params.pt"
LOCAL_DIR = os.path.join(os.getcwd(), "models", "qwen3_sentiment_tinystories")
weights_path = hf_hub_download(
repo_id=MODEL_REPO,
filename=FILENAME,
local_dir="qwen3_sentiment_tinystories", # any folder in runtime
local_dir_use_symlinks=None # not needed anymore; safe to omit
)
# Load classifier
classifier = SentimentClassifier(model_dir="qwen3_sentiment_tinystories",
weights_path=weights_path)
def predict_sentiment(text):
"""Predict sentiment and return results"""
result = classifier.predict(text)
return {
"Sentiment": result["sentiment"].upper(),
"Confidence": f"{result['confidence']:.2%}",
"Negative Probability": f"{result['probabilities']['negative']:.2%}",
"Positive Probability": f"{result['probabilities']['positive']:.2%}"
}
# Create interface
demo = gr.Interface(
fn=predict_sentiment,
inputs=gr.Textbox(
label="Enter text to analyze",
placeholder="Type your text here...",
lines=3
),
outputs=gr.JSON(label="Prediction Results"),
title="🎭 Sentiment Analyzer",
description="Classify text as positive or negative using Qwen3 embeddings + Logistic Regression",
examples=[
["This movie was absolutely wonderful!"],
["Terrible experience, complete waste of time."],
["It's okay, nothing special."]
]
)
demo.launch() |