Hasnain-Zainulabdin commited on
Commit
dd724c8
·
1 Parent(s): d7152f6

Add application file

Browse files
Files changed (3) hide show
  1. Dockerfile +16 -0
  2. app.py +18 -0
  3. requirements.txt +5 -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"]
app.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from pydantic import BaseModel
3
+ from transformers import pipeline
4
+
5
+ app = FastAPI()
6
+
7
+ nlp = pipeline("sentiment-analysis")
8
+
9
+ class PromptInput(BaseModel):
10
+ prompt: str
11
+
12
+ @app.post("/analyze")
13
+ def analyze_sentiment(prompt_input: PromptInput):
14
+ result = nlp(prompt_input.prompt)
15
+ return {
16
+ 'input': prompt_input.prompt,
17
+ 'output': result
18
+ }
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ torch
3
+ pydantic
4
+ uvicorn
5
+ transformers