Spaces:
Paused
Paused
Upload 3 files
Browse files- Dockerfile +14 -0
- app/main.py +33 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
# Install dependencies
|
| 6 |
+
COPY requirements.txt .
|
| 7 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 8 |
+
|
| 9 |
+
# Copy app code
|
| 10 |
+
COPY app ./app
|
| 11 |
+
|
| 12 |
+
EXPOSE 7860
|
| 13 |
+
|
| 14 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app/main.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from gradio_client import Client
|
| 4 |
+
|
| 5 |
+
# Configure your Gradio Space ID and default endpoint
|
| 6 |
+
SPACE_ID = "prithivMLmods/SAMBANOVA"
|
| 7 |
+
DEFAULT_API = "/chat"
|
| 8 |
+
|
| 9 |
+
client = Client(SPACE_ID)
|
| 10 |
+
|
| 11 |
+
def chat_with_gradio(message: str, api_name: str = DEFAULT_API):
|
| 12 |
+
"""
|
| 13 |
+
Send a chat message to the Gradio API and return the response.
|
| 14 |
+
"""
|
| 15 |
+
try:
|
| 16 |
+
return client.predict(message=message, api_name=api_name)
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return {"error": str(e)}
|
| 19 |
+
|
| 20 |
+
app = FastAPI()
|
| 21 |
+
|
| 22 |
+
class ChatRequest(BaseModel):
|
| 23 |
+
message: str
|
| 24 |
+
api_name: str = DEFAULT_API
|
| 25 |
+
|
| 26 |
+
@app.post("/chat")
|
| 27 |
+
async def chat_endpoint(req: ChatRequest):
|
| 28 |
+
return {"reply": chat_with_gradio(req.message, req.api_name)}
|
| 29 |
+
|
| 30 |
+
if __name__ == "__main__":
|
| 31 |
+
import uvicorn
|
| 32 |
+
print(f"Starting server on http://0.0.0.0:7860 using {SPACE_ID}{DEFAULT_API}")
|
| 33 |
+
uvicorn.run(app, host="0.0.0.0", port=7860)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
gradio-client
|