hpyapali commited on
Commit
d8b2f66
Β·
verified Β·
1 Parent(s): d3e207c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -9,7 +9,7 @@ from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
9
  import uvicorn
10
  import asyncio
11
 
12
- # βœ… Use float16 to reduce memory usage
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 (to prevent Space timeout)
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(webhook_url, json={"event_id": event_id, "data": [response_text]})
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: