Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- DockerFile +16 -0
- README.md +11 -11
- app.py +16 -0
- model.py +20 -0
- requirements.txt +4 -0
- static/style.css +7 -0
- templates/index.html +25 -0
DockerFile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.9
|
| 5 |
+
|
| 6 |
+
RUN useradd -m -u 1000 user
|
| 7 |
+
USER user
|
| 8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
| 1 |
-
---
|
| 2 |
-
title: MoodMeter
|
| 3 |
-
emoji: 📈
|
| 4 |
-
colorFrom: purple
|
| 5 |
-
colorTo: gray
|
| 6 |
-
sdk: docker
|
| 7 |
-
pinned: false
|
| 8 |
-
short_description: check your mood/emotions
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: MoodMeter
|
| 3 |
+
emoji: 📈
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
short_description: check your mood/emotions
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
from flask import Flask, render_template, request
|
| 3 |
+
from model import get_sentiment # Import your model function
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
@app.route('/', methods=['GET', 'POST'])
|
| 8 |
+
def index():
|
| 9 |
+
if request.method == 'POST':
|
| 10 |
+
user_input = request.form['user_input']
|
| 11 |
+
sentiment = get_sentiment(user_input) # Get sentiment from model
|
| 12 |
+
return render_template('index.html', input_text=user_input, result=sentiment)
|
| 13 |
+
return render_template('index.html') # Initial page load
|
| 14 |
+
|
| 15 |
+
if __name__ == '__main__':
|
| 16 |
+
app.run(debug=True)
|
model.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# model.py
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import DistilBertTokenizer, DistilBertForSequenceClassification
|
| 4 |
+
|
| 5 |
+
tokenizer = DistilBertTokenizer.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
+
model = DistilBertForSequenceClassification.from_pretrained("distilbert-base-uncased-finetuned-sst-2-english")
|
| 7 |
+
|
| 8 |
+
def get_sentiment(text):
|
| 9 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 10 |
+
with torch.no_grad():
|
| 11 |
+
logits = model(**inputs).logits
|
| 12 |
+
predicted_class_id = logits.argmax().item()
|
| 13 |
+
return model.config.id2label[predicted_class_id]
|
| 14 |
+
|
| 15 |
+
if __name__ == '__main__':
|
| 16 |
+
test_text = "This movie was NOt great!"
|
| 17 |
+
sentiment = get_sentiment(test_text)
|
| 18 |
+
print(f"Sentiment: {sentiment}")
|
| 19 |
+
|
| 20 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
torch
|
| 2 |
+
pandas
|
| 3 |
+
flask
|
| 4 |
+
transformers
|
static/style.css
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* static/style.css */
|
| 2 |
+
body {
|
| 3 |
+
font-family: sans-serif;
|
| 4 |
+
}
|
| 5 |
+
h1 {
|
| 6 |
+
color: #333;
|
| 7 |
+
}
|
templates/index.html
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Sentiment Analysis</title>
|
| 5 |
+
<link
|
| 6 |
+
rel="stylesheet"
|
| 7 |
+
type="text/css"
|
| 8 |
+
href="{{ url_for('static', filename='style.css') }}"
|
| 9 |
+
/>
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<h1>Sentiment Analysis</h1>
|
| 13 |
+
<form method="POST">
|
| 14 |
+
<label for="user_input">Enter 1 text:</label><br />
|
| 15 |
+
<textarea id="user_input" name="user_input" rows="4" cols="50">
|
| 16 |
+
{{ input_text or '' }}</textarea
|
| 17 |
+
><br /><br />
|
| 18 |
+
<input type="submit" value="Analyze" />
|
| 19 |
+
</form>
|
| 20 |
+
{% if result %}
|
| 21 |
+
<h2>Result:</h2>
|
| 22 |
+
<p>{{ result }}</p>
|
| 23 |
+
{% endif %}
|
| 24 |
+
</body>
|
| 25 |
+
</html>
|