Spaces:
Sleeping
Sleeping
devcool20
commited on
Commit
·
f0d9284
1
Parent(s):
78fb7e6
Initial application upload
Browse files- .gitattributes +1 -0
- .gitignore +12 -0
- Dockerfile +18 -0
- app.py +46 -0
- config.json +39 -0
- logo_no_bg.png +3 -0
- merges.txt +0 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
- requirements.txt +10 -0
- special_tokens_map.json +1 -0
- tokenizer.json +0 -0
- tokenizer_config.json +1 -0
- training_args.bin +3 -0
- vocab.json +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Environment variables and secrets
|
| 2 |
+
.env
|
| 3 |
+
|
| 4 |
+
# Jupyter Notebook checkpoints
|
| 5 |
+
.ipynb_checkpoints/
|
| 6 |
+
|
| 7 |
+
# Local log/run directories
|
| 8 |
+
runs/
|
| 9 |
+
|
| 10 |
+
# Python cache
|
| 11 |
+
__pycache__/
|
| 12 |
+
*.pyc
|
Dockerfile
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use an official Python runtime as a parent image
|
| 2 |
+
FROM python:3.9-slim
|
| 3 |
+
|
| 4 |
+
# Set the working directory in the container
|
| 5 |
+
WORKDIR /code
|
| 6 |
+
|
| 7 |
+
# Copy the requirements file into the container
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
# Install any needed packages specified in requirements.txt
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 12 |
+
|
| 13 |
+
# Copy the rest of your application's code and model files into the container
|
| 14 |
+
COPY . /code/
|
| 15 |
+
|
| 16 |
+
# Set the command to run your app using gunicorn, a production-ready server
|
| 17 |
+
# We use port 7860 as it's standard for Hugging Face Spaces
|
| 18 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "app:app"]
|
app.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from flask import Flask, request, jsonify
|
| 3 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
| 4 |
+
from flask_cors import CORS
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
CORS(app)
|
| 8 |
+
|
| 9 |
+
# --- CHANGE IS HERE ---
|
| 10 |
+
# Define the local directory path where your model files are located.
|
| 11 |
+
# The "." means the current directory.
|
| 12 |
+
local_model_path = "."
|
| 13 |
+
print(f"Loading model from local path: {local_model_path}")
|
| 14 |
+
|
| 15 |
+
# Load the model and tokenizer from the local directory
|
| 16 |
+
try:
|
| 17 |
+
tokenizer = AutoTokenizer.from_pretrained(local_model_path)
|
| 18 |
+
model = AutoModelForSequenceClassification.from_pretrained(local_model_path)
|
| 19 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 20 |
+
print("Model loaded successfully.")
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"Error loading model: {e}")
|
| 23 |
+
# If the model fails to load, we can't run the app. Exit or handle appropriately.
|
| 24 |
+
classifier = None
|
| 25 |
+
|
| 26 |
+
@app.route('/analyze', methods=['POST'])
|
| 27 |
+
def analyze_sentiment():
|
| 28 |
+
if not classifier:
|
| 29 |
+
return jsonify({"error": "Model could not be loaded. Check server logs."}), 500
|
| 30 |
+
|
| 31 |
+
data = request.json
|
| 32 |
+
text = data.get('text', '')
|
| 33 |
+
|
| 34 |
+
if not text:
|
| 35 |
+
return jsonify({"error": "No text provided"}), 400
|
| 36 |
+
|
| 37 |
+
try:
|
| 38 |
+
result = classifier(text)
|
| 39 |
+
return jsonify(result)
|
| 40 |
+
except Exception as e:
|
| 41 |
+
print(f"Error during analysis: {e}")
|
| 42 |
+
return jsonify({"error": str(e)}), 500
|
| 43 |
+
|
| 44 |
+
if __name__ == '__main__':
|
| 45 |
+
port = int(os.environ.get("PORT", 8080))
|
| 46 |
+
app.run(host='0.0.0.0', port=port)
|
config.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "distilroberta-base",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"RobertaForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"eos_token_id": 2,
|
| 10 |
+
"gradient_checkpointing": false,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 768,
|
| 14 |
+
"id2label": {
|
| 15 |
+
"0": "negative",
|
| 16 |
+
"1": "neutral",
|
| 17 |
+
"2": "positive"
|
| 18 |
+
},
|
| 19 |
+
"initializer_range": 0.02,
|
| 20 |
+
"intermediate_size": 3072,
|
| 21 |
+
"label2id": {
|
| 22 |
+
"negative": 0,
|
| 23 |
+
"neutral": 1,
|
| 24 |
+
"positive": 2
|
| 25 |
+
},
|
| 26 |
+
"layer_norm_eps": 1e-05,
|
| 27 |
+
"max_position_embeddings": 514,
|
| 28 |
+
"model_type": "roberta",
|
| 29 |
+
"num_attention_heads": 12,
|
| 30 |
+
"num_hidden_layers": 6,
|
| 31 |
+
"pad_token_id": 1,
|
| 32 |
+
"position_embedding_type": "absolute",
|
| 33 |
+
"problem_type": "single_label_classification",
|
| 34 |
+
"torch_dtype": "float32",
|
| 35 |
+
"transformers_version": "4.10.2",
|
| 36 |
+
"type_vocab_size": 1,
|
| 37 |
+
"use_cache": true,
|
| 38 |
+
"vocab_size": 50265
|
| 39 |
+
}
|
logo_no_bg.png
ADDED
|
Git LFS Details
|
merges.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c0b61385e4482edd179b69042c014dcb53a79431784f34a0171f5d43b092feaa
|
| 3 |
+
size 328499560
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c6d24cd7c45f0b65241fd9ff1aa97814eea3ab7bdbf1458248fb9f4b2c817864
|
| 3 |
+
size 328529005
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask==2.0.1
|
| 2 |
+
flask-cors==3.0.10
|
| 3 |
+
transformers>=4.35.0
|
| 4 |
+
torch>=2.0.0
|
| 5 |
+
torchvision>=0.15.0
|
| 6 |
+
datasets>=1.12.1
|
| 7 |
+
tokenizers>=0.13.0
|
| 8 |
+
werkzeug>=2.0.0,<2.1.0
|
| 9 |
+
sentencepiece
|
| 10 |
+
gunicorn
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": false}}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"unk_token": "<unk>", "bos_token": "<s>", "eos_token": "</s>", "add_prefix_space": false, "errors": "replace", "sep_token": "</s>", "cls_token": "<s>", "pad_token": "<pad>", "mask_token": "<mask>", "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "distilroberta-base", "tokenizer_class": "RobertaTokenizer"}
|
training_args.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ee1178219233a39de3467c1d1c9ad2fd1d976e51b9ed6bb5a459131607445eaf
|
| 3 |
+
size 2735
|
vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|