Spaces:
Paused
Paused
Delete main.py
Browse files
main.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|