Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
|
9 |
import uvicorn
|
10 |
import asyncio
|
11 |
|
12 |
-
# β
|
13 |
torch.set_default_dtype(torch.float16)
|
14 |
|
15 |
# β
Hugging Face API Token
|
@@ -17,9 +17,12 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
17 |
MODEL_NAME = "hpyapali/tinyllama-workout"
|
18 |
event_store = {} # Store AI responses for polling fallback
|
19 |
|
|
|
|
|
|
|
20 |
app = FastAPI()
|
21 |
|
22 |
-
# β
Lazy Load AI Model (
|
23 |
pipe = None
|
24 |
|
25 |
def get_pipeline():
|
@@ -85,11 +88,9 @@ async def process_workout_request(request: Request):
|
|
85 |
event_store[event_id] = response_text
|
86 |
|
87 |
# β
Send AI response to Vapor Webhook
|
88 |
-
webhook_url = "https://694a-50-35-76-93.ngrok-free.app/fineTuneModel"
|
89 |
-
|
90 |
async with httpx.AsyncClient() as client:
|
91 |
try:
|
92 |
-
webhook_response = await client.post(
|
93 |
webhook_response.raise_for_status()
|
94 |
print(f"β
Webhook sent successfully: {webhook_response.json()}")
|
95 |
except Exception as e:
|
|
|
9 |
import uvicorn
|
10 |
import asyncio
|
11 |
|
12 |
+
# β
Reduce memory usage by setting float16 precision
|
13 |
torch.set_default_dtype(torch.float16)
|
14 |
|
15 |
# β
Hugging Face API Token
|
|
|
17 |
MODEL_NAME = "hpyapali/tinyllama-workout"
|
18 |
event_store = {} # Store AI responses for polling fallback
|
19 |
|
20 |
+
# β
Webhook URL (Your Vapor Webhook Server)
|
21 |
+
WEBHOOK_URL = "https://694a-50-35-76-93.ngrok-free.app/fineTuneModel"
|
22 |
+
|
23 |
app = FastAPI()
|
24 |
|
25 |
+
# β
Lazy Load AI Model (prevents timeout on Hugging Face)
|
26 |
pipe = None
|
27 |
|
28 |
def get_pipeline():
|
|
|
88 |
event_store[event_id] = response_text
|
89 |
|
90 |
# β
Send AI response to Vapor Webhook
|
|
|
|
|
91 |
async with httpx.AsyncClient() as client:
|
92 |
try:
|
93 |
+
webhook_response = await client.post(WEBHOOK_URL, json={"event_id": event_id, "data": [response_text]})
|
94 |
webhook_response.raise_for_status()
|
95 |
print(f"β
Webhook sent successfully: {webhook_response.json()}")
|
96 |
except Exception as e:
|