Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,11 +3,9 @@ from pydantic import BaseModel
|
|
| 3 |
from llama_cpp import Llama
|
| 4 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 5 |
import uvicorn
|
| 6 |
-
import huggingface_hub
|
| 7 |
import re
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
import spaces
|
| 10 |
-
from spaces import *
|
| 11 |
|
| 12 |
load_dotenv()
|
| 13 |
|
|
@@ -115,10 +113,10 @@ def remove_repetitive_responses(responses):
|
|
| 115 |
|
| 116 |
@spaces.GPU(duration=0)
|
| 117 |
def generate_chat_response(request, model_data):
|
|
|
|
| 118 |
try:
|
| 119 |
user_input = normalize_input(request.message)
|
| 120 |
-
|
| 121 |
-
response = llm(user_input, top_k=request.top_k, top_p=request.top_p, temperature=request.temperature)
|
| 122 |
return {"model": model_data['name'], "response": response}
|
| 123 |
except Exception:
|
| 124 |
pass
|
|
@@ -149,5 +147,12 @@ async def generate(request: ChatRequest):
|
|
| 149 |
except Exception:
|
| 150 |
pass
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
if __name__ == "__main__":
|
| 153 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 3 |
from llama_cpp import Llama
|
| 4 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 5 |
import uvicorn
|
|
|
|
| 6 |
import re
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
import spaces
|
|
|
|
| 9 |
|
| 10 |
load_dotenv()
|
| 11 |
|
|
|
|
| 113 |
|
| 114 |
@spaces.GPU(duration=0)
|
| 115 |
def generate_chat_response(request, model_data):
|
| 116 |
+
model = model_data['model']
|
| 117 |
try:
|
| 118 |
user_input = normalize_input(request.message)
|
| 119 |
+
response = model(user_input, top_k=request.top_k, top_p=request.top_p, temperature=request.temperature)
|
|
|
|
| 120 |
return {"model": model_data['name'], "response": response}
|
| 121 |
except Exception:
|
| 122 |
pass
|
|
|
|
| 147 |
except Exception:
|
| 148 |
pass
|
| 149 |
|
| 150 |
+
@app.api_route("/{method_name}", methods=["GET", "POST", "PUT", "DELETE", "PATCH"])
|
| 151 |
+
async def handle_request(method_name: str):
|
| 152 |
+
try:
|
| 153 |
+
return {"message": "Request handled successfully"}
|
| 154 |
+
except Exception:
|
| 155 |
+
raise HTTPException(status_code=500, detail="Error: Internal Server Error")
|
| 156 |
+
|
| 157 |
if __name__ == "__main__":
|
| 158 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|