spacesedan commited on
Commit
1ed9d03
·
1 Parent(s): b37307d

feat added bert application file

Browse files
Files changed (4) hide show
  1. .gitignore +40 -0
  2. Dockerfile +18 -0
  3. app.py +20 -0
  4. requirements.txt +4 -0
.gitignore ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Ignore Python cache files
2
+ __pycache__/
3
+ *.pyc
4
+ *.pyo
5
+ *.pyd
6
+ *.pyo
7
+ *.pdb
8
+ *.egg-info/
9
+ *.log
10
+
11
+ # Ignore virtual environments
12
+ venv/
13
+ env/
14
+ pip-log.txt
15
+ pip-delete-this-directory.txt
16
+
17
+ # Ignore local Hugging Face cache (to avoid unnecessary large files)
18
+ .huggingface/
19
+ .cache/
20
+ datasets/
21
+
22
+ # Ignore Docker build artifacts
23
+ *.dockerignore
24
+ *.tar
25
+ *.img
26
+ *.iso
27
+ .DS_Store
28
+
29
+ # Ignore Hugging Face Space build files
30
+ logs/
31
+ output/
32
+ tmp/
33
+ config.json
34
+ hf-token
35
+
36
+ # Ignore system files
37
+ Thumbs.db
38
+ .DS_Store
39
+ .idea/
40
+ .vscode/
Dockerfile ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ # Create a non-root user for security
4
+ RUN useradd -m -u 1000 user
5
+ USER user
6
+ ENV PATH="/home/user/.local/bin:$PATH"
7
+
8
+ WORKDIR /app
9
+
10
+ # Install dependencies
11
+ COPY --chown=user ./requirements.txt requirements.txt
12
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
13
+
14
+ # Copy application files
15
+ COPY --chown=user . /app
16
+
17
+ # Run the FastAPI app
18
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ app = FastAPI()
6
+
7
+ sentiment_analyzer = pipeline("sentiment-analysis", model="nlptown/bert-base-multilingual-uncased-sentiment")
8
+
9
+ class SentimentRequest(BaseModel):
10
+ text: str
11
+
12
+ @app.post("/sentiment")
13
+ async def analyze_sentiment(request: SentimentRequest):
14
+ result = sentiment_analyzer(request.text)
15
+ print(result)
16
+ return {"label": result[0]["label"], "score": result[0]["score"]}
17
+
18
+ @app.get("/")
19
+ def greet_json():
20
+ return {"message": "BERT Sentiment Analysis API is running!"}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ torch
4
+ transformers