Nav772 commited on
Commit
2244353
·
verified ·
1 Parent(s): 9db23ec

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ # Load both models
6
+ distilbert = pipeline(
7
+ "text-classification",
8
+ model="Nav772/distilbert-amazon-reviews-5star"
9
+ )
10
+
11
+ roberta = pipeline(
12
+ "text-classification",
13
+ model="Nav772/roberta-amazon-reviews-5star"
14
+ )
15
+
16
+ def compare_models(text):
17
+ if not text.strip():
18
+ return "Please enter a review.", "Please enter a review."
19
+
20
+ # Get predictions from both models
21
+ distilbert_result = distilbert(text)[0]
22
+ roberta_result = roberta(text)[0]
23
+
24
+ # Format outputs
25
+ distilbert_stars = "⭐" * int(distilbert_result["label"][0])
26
+ roberta_stars = "⭐" * int(roberta_result["label"][0])
27
+
28
+ distilbert_output = f"{distilbert_stars}\n{distilbert_result['label']}\nConfidence: {distilbert_result['score']:.2%}"
29
+ roberta_output = f"{roberta_stars}\n{roberta_result['label']}\nConfidence: {roberta_result['score']:.2%}"
30
+
31
+ return distilbert_output, roberta_output
32
+
33
+ demo = gr.Interface(
34
+ fn=compare_models,
35
+ inputs=gr.Textbox(
36
+ label="Enter a product review",
37
+ placeholder="Type your review here...",
38
+ lines=4
39
+ ),
40
+ outputs=[
41
+ gr.Textbox(label="DistilBERT (67M params, faster)"),
42
+ gr.Textbox(label="RoBERTa (125M params, more accurate)")
43
+ ],
44
+ title="🔬 Model Comparison: DistilBERT vs RoBERTa",
45
+ description="Compare two transformer models on the same review. Both were fine-tuned on Amazon product reviews for 5-star rating prediction.",
46
+ examples=[
47
+ ["This product exceeded all my expectations! Incredible quality and fast shipping."],
48
+ ["Meh. It works I guess. Nothing special about it."],
49
+ ["DO NOT BUY. Arrived broken and customer service was unhelpful."],
50
+ ["Pretty good for the price. Some minor issues but overall satisfied."]
51
+ ],
52
+ theme="soft"
53
+ )
54
+
55
+ demo.launch()