Spaces:
Running
Running
manue
commited on
Commit
·
7106645
1
Parent(s):
74b7079
Add initial project files including Dockerfile, app, sentiment model, requirements, and .gitignore
Browse files- .gitignore +2 -0
- Dockerfile +12 -0
- app.py +22 -0
- model/sentiment.py +8 -0
- requirements.txt +0 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
env/
|
2 |
+
__pycache__/
|
Dockerfile
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
COPY . /app
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
8 |
+
|
9 |
+
EXPOSE 5000
|
10 |
+
EXPOSE 7860
|
11 |
+
|
12 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, jsonify, request
|
2 |
+
from flask_cors import CORS
|
3 |
+
|
4 |
+
from model.sentiment import Sentiment
|
5 |
+
from urllib.parse import unquote
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
CORS(app)
|
9 |
+
|
10 |
+
@app.route('/analisis', methods=['GET'])
|
11 |
+
def analisis():
|
12 |
+
prompt = request.args.get('prompt')
|
13 |
+
prompt = unquote(request.args.get('prompt', ''))
|
14 |
+
|
15 |
+
if not prompt:
|
16 |
+
return jsonify({"error": "No prompt provided"}), 400
|
17 |
+
|
18 |
+
model = Sentiment(prompt)
|
19 |
+
return jsonify({"message": model.result}), 200
|
20 |
+
|
21 |
+
if __name__ == '__main__':
|
22 |
+
app.run(debug=True)
|
model/sentiment.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
from typing import Any
|
3 |
+
|
4 |
+
class Sentiment:
|
5 |
+
def __init__(self, line: str) -> (list | list[Any] | Any | None):
|
6 |
+
self.pipe = pipeline("text-classification", model="MilaNLProc/feel-it-italian-sentiment")
|
7 |
+
self.result = self.pipe(line)
|
8 |
+
|
requirements.txt
ADDED
Binary file (1.14 kB). View file
|
|