vanhai123 commited on
Commit
38ccb65
·
verified ·
1 Parent(s): 3456608

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +50 -14
  2. app.py +24 -0
  3. requirements.txt +3 -0
README.md CHANGED
@@ -1,14 +1,50 @@
1
- ---
2
- title: Sentiment Analyzer
3
- emoji: 🚀
4
- colorFrom: blue
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 5.32.0
8
- app_file: app.py
9
- pinned: false
10
- license: apache-2.0
11
- short_description: Phân tích cảm xúc câu tiếng Anh (tích cực hoặc tiêu cực) bằn
12
- ---
13
-
14
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Sentiment Analysis App (Hugging Face Spaces)
2
+
3
+ Một ứng dụng đơn giản sử dụng mô hình có sẵn từ Hugging Face để phân tích cảm xúc (tích cực hoặc tiêu cực) của văn bản tiếng Anh.
4
+
5
+ ## 🚀 Demo
6
+
7
+ 🔗 Truy cập ứng dụng tại: [https://huggingface.co/spaces/<your-username>/<your-repo>](https://huggingface.co/spaces)
8
+
9
+ ## 📌 Mô tả
10
+
11
+ Ứng dụng này sử dụng hình `distilbert-base-uncased-finetuned-sst-2-english` từ thư viện `transformers` để thực hiện phân tích cảm xúc.
12
+
13
+ - 📥 Nhập một câu văn bằng tiếng Anh.
14
+ - 📊 Hệ thống sẽ trả về nhãn cảm xúc: `POSITIVE` hoặc `NEGATIVE`, cùng với độ tin cậy (%).
15
+
16
+ ## 🧰 Công nghệ sử dụng
17
+
18
+ - [🤗 Transformers](https://huggingface.co/transformers/)
19
+ - [Gradio](https://www.gradio.app/)
20
+ - [PyTorch](https://pytorch.org/)
21
+
22
+ ## 📁 Cấu trúc thư mục
23
+
24
+ ```
25
+ .
26
+ ├── app.py # Code ứng dụng Gradio
27
+ ├── requirements.txt # Các thư viện cần thiết
28
+ └── README.md # File mô tả dự án
29
+ ```
30
+
31
+ ## 📆 requirements.txt
32
+
33
+ ```txt
34
+ transformers
35
+ torch
36
+ gradio
37
+ ```
38
+
39
+ ## 🛠 Cách chạy local (tùy chọn)
40
+
41
+ ```bash
42
+ pip install -r requirements.txt
43
+ python app.py
44
+ ```
45
+
46
+ ## ✨ Giao diện
47
+
48
+ - Giao diện đơn giản bằng Gradio
49
+ - Có thể mở rộng để xử lý văn bản tiếng Việt hoặc tích hợp API
50
+
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Tải model phân tích cảm xúc từ Hugging Face Hub
5
+ sentiment_model = pipeline("sentiment-analysis")
6
+
7
+ # Hàm xử lý đầu vào
8
+ def analyze_sentiment(text):
9
+ result = sentiment_model(text)[0]
10
+ label = result['label']
11
+ score = round(result['score'] * 100, 2)
12
+ return f"Kết quả: {label} ({score}%)"
13
+
14
+ # Giao diện Gradio
15
+ interface = gr.Interface(
16
+ fn=analyze_sentiment,
17
+ inputs=gr.Textbox(lines=2, placeholder="Nhập câu của bạn..."),
18
+ outputs="text",
19
+ title="Phân tích cảm xúc",
20
+ description="Nhập một câu tiếng Anh để phân tích cảm xúc (tích cực / tiêu cực)."
21
+ )
22
+
23
+ # Chạy ứng dụng
24
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio