Spaces:
Sleeping
Sleeping
manue
commited on
Commit
·
7e8513d
1
Parent(s):
a471f05
Remove unused environment variable and improve error handling in analysis endpoint
Browse files- Dockerfile +0 -2
- app.py +5 -2
- model/sentiment.py +2 -1
Dockerfile
CHANGED
|
@@ -4,8 +4,6 @@ WORKDIR /app
|
|
| 4 |
|
| 5 |
COPY . /app
|
| 6 |
|
| 7 |
-
ENV HUGGINGFACE_DISABLE_CACHE=1
|
| 8 |
-
|
| 9 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 10 |
|
| 11 |
CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app"]
|
|
|
|
| 4 |
|
| 5 |
COPY . /app
|
| 6 |
|
|
|
|
|
|
|
| 7 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
|
| 9 |
CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app"]
|
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
| 3 |
|
| 4 |
from flask import Flask, jsonify, request
|
|
@@ -10,14 +11,16 @@ from urllib.parse import unquote
|
|
| 10 |
app = Flask(__name__)
|
| 11 |
CORS(app)
|
| 12 |
|
|
|
|
| 13 |
@app.route('/')
|
| 14 |
def home():
|
| 15 |
return jsonify({"message": "API is running!"})
|
| 16 |
|
|
|
|
| 17 |
@app.route('/analisis', methods=['GET'])
|
| 18 |
def analisis():
|
| 19 |
-
prompt = request.args.get('prompt')
|
| 20 |
-
prompt = unquote(
|
| 21 |
|
| 22 |
if not prompt:
|
| 23 |
return jsonify({"error": "No prompt provided"}), 400
|
|
|
|
| 1 |
import os
|
| 2 |
+
# Default /.cache/huggingface ci vengono scaricati i modelli
|
| 3 |
os.environ["HF_HOME"] = "/tmp/huggingface"
|
| 4 |
|
| 5 |
from flask import Flask, jsonify, request
|
|
|
|
| 11 |
app = Flask(__name__)
|
| 12 |
CORS(app)
|
| 13 |
|
| 14 |
+
# Endpoint '/'
|
| 15 |
@app.route('/')
|
| 16 |
def home():
|
| 17 |
return jsonify({"message": "API is running!"})
|
| 18 |
|
| 19 |
+
# Endpoint '/analisis'
|
| 20 |
@app.route('/analisis', methods=['GET'])
|
| 21 |
def analisis():
|
| 22 |
+
prompt = request.args.get('prompt', '')
|
| 23 |
+
prompt = unquote(prompt)
|
| 24 |
|
| 25 |
if not prompt:
|
| 26 |
return jsonify({"error": "No prompt provided"}), 400
|
model/sentiment.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 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 |
|
|
|
|
| 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 = this in C#
|
| 7 |
self.pipe = pipeline("text-classification", model="MilaNLProc/feel-it-italian-sentiment")
|
| 8 |
self.result = self.pipe(line)
|
| 9 |
|