gokulan006 commited on
Commit
ae38b15
Β·
verified Β·
1 Parent(s): cf07c75

Uploading food not food text classifier demo app.py

Browse files
Files changed (3) hide show
  1. README.md +11 -5
  2. app.py +46 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,18 @@
1
  ---
2
- title: IMDB Sentimental Analysis
3
- emoji: 🐠
4
  colorFrom: blue
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 5.14.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
1
  ---
2
+ title: IMDB SENTIMENTAL ANALYSIS
3
+ emoji: πŸ“πŸŽ¬πŸŽ₯
4
  colorFrom: blue
5
+ colorTo: yellow
6
  sdk: gradio
 
7
  app_file: app.py
8
  pinned: false
9
+ license: apache-2.0
10
  ---
11
 
12
+ # Food Not Food Text Classifier
13
+
14
+ Small demo to showcase a text classifier to determine if a movie review is positive or negative.
15
+
16
+ DistillBERT model fine-tuned on a small synthetic dataset of 250 generated [Food or Not Food image captions](https://github.com/gokulan006/IMDB-Sentiment-Analysis/raw/refs/heads/master/IMDB%20Dataset.csv).
17
+
18
+
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 1. Import the required packages
2
+ import torch
3
+ import gradio as gr
4
+
5
+ from typing import Dict
6
+ from transformers import pipeline
7
+
8
+ # 2. Define function to use our model on given text
9
+ def IMDB_sentimental_analysis(text: str) -> Dict[str, float]:
10
+ # Set up text classification pipeline
11
+ IMDB_sentimental_analysis = pipeline(task="text-classification",
12
+ # Because our model is on Hugging Face already, we can pass in the model name directly
13
+ model="gokulan006/IMDB_sentimental_analysis-distilbert-base-uncased", # link to model on HF Hub
14
+ device="cuda" if torch.cuda.is_available() else "cpu",
15
+ top_k=None) # return all possible scores (not just top-1)
16
+
17
+ # Get outputs from pipeline (as a list of dicts)
18
+ outputs = IMDB_sentimental_analysis(text)[0]
19
+
20
+ # Format output for Gradio (e.g. {"label_1": probability_1, "label_2": probability_2})
21
+ output_dict = {}
22
+ for item in outputs:
23
+ output_dict[item["label"]] = item["score"]
24
+
25
+ return output_dict
26
+
27
+ # 3. Create a Gradio interface with details about our app
28
+ description = """
29
+ A text classifier to determine if a movie review is positive or negative.
30
+
31
+ Fine-tuned from [DistilBERT](https://huggingface.co/distilbert/distilbert-base-uncased) on a [small dataset of food and not food text](https://github.com/gokulan006/IMDB-Sentiment-Analysis/raw/refs/heads/master/IMDB%20Dataset.csv).
32
+
33
+
34
+ """
35
+
36
+ demo = gr.Interface(fn=IMDB_sentimental_analysis,
37
+ inputs="text",
38
+ outputs=gr.Label(num_top_classes=2), # show top 2 classes (that's all we have)
39
+ title="πŸ“πŸŽ¬πŸŽ₯ IMDB SENTIMENTAL ANALYSIS",
40
+ description=description,
41
+ examples=[["A visually stunning and thought-provoking film that dares to take its time. Denis Villeneuve masterfully crafts a slow-burn neo-noir that expands upon the themes of identity and humanity introduced in the original Blade Runner. While some may find the pacing too slow, those who appreciate deep, atmospheric storytelling will find it incredibly rewarding. The cinematography by Roger Deakins is breathtaking, and the score perfectly complements the film’s futuristic yet melancholic tone. A near-perfect sequel, though it may not be for everyone."],
42
+ ["This movie is a complete disaster. The jokes are forced, the script makes no sense, and the humor is cringeworthy. I can't believe such a talented cast was wasted in this mess. It’s painfully unfunny, and I regret spending my time on it."]])
43
+
44
+ # 4. Launch the interface
45
+ if __name__ == "__main__":
46
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ torch
3
+ transformers