McKlay commited on
Commit
e13ffcc
Β·
0 Parent(s):

πŸš€ Deploy Hugging Face Gradio version with updated README

Browse files
Files changed (4) hide show
  1. .gitignore +21 -0
  2. README.md +51 -0
  3. app.py +26 -0
  4. requirements.txt +3 -0
.gitignore ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python virtual environment
2
+ venv/
3
+ __pycache__/
4
+ *.pyc
5
+
6
+ # VSCode & OS junk
7
+ .vscode/
8
+ .DS_Store
9
+
10
+ # Environment files
11
+ .env
12
+ .env.*
13
+
14
+ # Model folders (only ignore unnecessary subfolders)
15
+ model/__results__files/
16
+ model/results.zip
17
+ model/sentiment_model/
18
+ model/*__huggingface_repo__*
19
+
20
+ # Don't ignore actual model files that are used!
21
+ # Keep: model.safetensors, tokenizer.json, config.json, etc.
README.md ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 🧠 Sentiment Analysis V2 (Gradio Version)
2
+
3
+ A lightweight sentiment classification web app using a fine-tuned **BERT** model.
4
+
5
+ > Hosted entirely on [πŸ€— Hugging Face Spaces](https://huggingface.co/spaces/McKlay/SentimentAnalysisV2-HF) using **Gradio** and **Transformers**.
6
+
7
+ ---
8
+
9
+ ## βš™οΈ Tech Stack
10
+ - πŸ€— **Transformers** for BERT-based text classification
11
+ - πŸ”₯ **PyTorch** for model inference
12
+ - 🎨 **Gradio** for building the web interface
13
+ - πŸš€ **Hugging Face Spaces** for free app hosting
14
+
15
+ ---
16
+
17
+ ## πŸ§ͺ Try It Out
18
+ Paste a sentence into the textbox and get real-time sentiment probabilities (positive/negative) with confidence levels.
19
+
20
+ ---
21
+
22
+ ## πŸ“ File Structure
23
+ SentimentAnalysisV2-HF/
24
+ β”œβ”€β”€ app.py # Main Gradio app
25
+ β”œβ”€β”€ model/ # empty, the model is located in model hub McKlay/sentiment-analysis-v2
26
+ β”œβ”€β”€ requirements.txt # Dependency file
27
+ β”œβ”€β”€ .gitignore └── README.md
28
+
29
+ ---
30
+
31
+ ## βœ… How It Works
32
+
33
+ 1. Loads the tokenizer and model from the `model/` folder.
34
+ 2. Processes input text and runs inference using BERT.
35
+ 3. Returns the confidence scores for each sentiment label.
36
+ 4. All of this happens **live** in your browser via Gradio!
37
+
38
+ ---
39
+
40
+ ## ✨ Author
41
+
42
+ **Clay Mark Sarte**
43
+ [GitHub: @McKlay](https://github.com/McKlay)
44
+ Passionate about AI, ML, and building useful tools with minimal stack.
45
+
46
+ ---
47
+
48
+ ## πŸ“œ License
49
+
50
+ MIT License β€” free to use and modify.
51
+
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import BertTokenizer, BertForSequenceClassification
3
+ import torch
4
+
5
+ # Load model and tokenizer from Hugging Face Hub
6
+ MODEL_DIR = "McKlay/sentiment-analysis-v2"
7
+ tokenizer = BertTokenizer.from_pretrained(MODEL_DIR)
8
+ model = BertForSequenceClassification.from_pretrained(MODEL_DIR)
9
+ model.eval()
10
+
11
+ # Define prediction function
12
+ def analyze_sentiment(text):
13
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
14
+ outputs = model(**inputs)
15
+ probs = torch.nn.functional.softmax(outputs.logits, dim=1)
16
+ labels = ['Negative', 'Positive']
17
+ return {labels[i]: float(probs[0][i]) for i in range(2)}
18
+
19
+ # Launch Gradio interface
20
+ gr.Interface(
21
+ fn=analyze_sentiment,
22
+ inputs=gr.Textbox(lines=3, placeholder="Enter a comment..."),
23
+ outputs=gr.Label(num_top_classes=2),
24
+ title="Sentiment Analysis V2 (Gradio)",
25
+ description="Real-time sentiment analysis using a BERT-based model. Powered by πŸ€— Transformers and Gradio."
26
+ ).launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio