Spaces:
Runtime error
Runtime error
Prathamesh Khade
commited on
Commit
·
5702872
1
Parent(s):
b22b5d4
Deploy new version
Browse files- .github/workflows/deploy.yml +39 -0
- Docker +17 -0
- README.md +2 -11
- app/main.py +32 -0
- app/requirements.txt +4 -0
.github/workflows/deploy.yml
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
name: Deploy FastAPI to Hugging Face Spaces
|
2 |
+
|
3 |
+
on:
|
4 |
+
push:
|
5 |
+
branches:
|
6 |
+
- main
|
7 |
+
|
8 |
+
jobs:
|
9 |
+
deploy:
|
10 |
+
runs-on: ubuntu-latest
|
11 |
+
|
12 |
+
steps:
|
13 |
+
- name: Checkout repository
|
14 |
+
uses: actions/checkout@v3
|
15 |
+
|
16 |
+
- name: Install Hugging Face CLI
|
17 |
+
run: pip install huggingface_hub
|
18 |
+
|
19 |
+
- name: Authenticate with Hugging Face
|
20 |
+
env:
|
21 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
22 |
+
run: huggingface-cli login --token "$HF_TOKEN"
|
23 |
+
|
24 |
+
- name: Clone Hugging Face Space
|
25 |
+
env:
|
26 |
+
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
27 |
+
run: |
|
28 |
+
git clone https://user:[email protected]/spaces/Prathamesh1420/fastapi-chatbot
|
29 |
+
mv fastapi-chatbot hf_space
|
30 |
+
rsync -av --exclude=hf_space --exclude=.git ./ hf_space/
|
31 |
+
cd hf_space
|
32 |
+
|
33 |
+
# Set Git User Identity
|
34 |
+
git config --global user.email "[email protected]"
|
35 |
+
git config --global user.name "Prathamesh Khade"
|
36 |
+
|
37 |
+
git add .
|
38 |
+
git commit -m "Deploy new version"
|
39 |
+
git push
|
Docker
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Use Python official image
|
2 |
+
FROM python:3.10
|
3 |
+
|
4 |
+
# Set the working directory
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
# Copy project files
|
8 |
+
COPY . /app
|
9 |
+
|
10 |
+
# Install dependencies
|
11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
12 |
+
|
13 |
+
# Expose the port FastAPI runs on
|
14 |
+
EXPOSE 7860
|
15 |
+
|
16 |
+
# Run the FastAPI app with Uvicorn
|
17 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -1,11 +1,2 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
emoji: 📚
|
4 |
-
colorFrom: pink
|
5 |
-
colorTo: indigo
|
6 |
-
sdk: docker
|
7 |
-
pinned: false
|
8 |
-
short_description: project
|
9 |
-
---
|
10 |
-
|
11 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
+
# Hugging_face_with_docker
|
2 |
+
Project
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app/main.py
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#import libraries
|
2 |
+
from fastapi import FastAPI, HTTPException
|
3 |
+
from pydantic import BaseModel
|
4 |
+
from transformers import pipeline
|
5 |
+
import uvicorn
|
6 |
+
|
7 |
+
# Initialize FastAPI app
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
# Load the Hugging Face question-answering model
|
11 |
+
qa_pipeline = pipeline("question-answering", model="distilbert-base-uncased-distilled-squad")
|
12 |
+
|
13 |
+
# Define request and response models
|
14 |
+
class ChatRequest(BaseModel):
|
15 |
+
question: str
|
16 |
+
context: str
|
17 |
+
|
18 |
+
class ChatResponse(BaseModel):
|
19 |
+
answer: str
|
20 |
+
|
21 |
+
# Define the /chat endpoint
|
22 |
+
@app.post("/chat", response_model=ChatResponse)
|
23 |
+
async def chat(request: ChatRequest):
|
24 |
+
try:
|
25 |
+
result = qa_pipeline(question=request.question, context=request.context)
|
26 |
+
return ChatResponse(answer=result['answer'])
|
27 |
+
except Exception as e:
|
28 |
+
raise HTTPException(status_code=500, detail=str(e))
|
29 |
+
|
30 |
+
# Run the FastAPI server
|
31 |
+
if __name__ == "__main__":
|
32 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
app/requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
transformers
|
4 |
+
pydantic
|