bealimehdi commited on
Commit
36e370a
·
verified ·
1 Parent(s): 2257304

One last time 001

Browse files
Files changed (1) hide show
  1. services/ai_service.py +14 -3
services/ai_service.py CHANGED
@@ -105,9 +105,20 @@ class AIService:
105
  import shutil
106
  shutil.copy(generated_path, destination)
107
 
108
- # Convert absolute path to local URL for frontend
109
- # assuming running on localhost:8000
110
- return f"http://localhost:8000/static/{output_filename}"
 
 
 
 
 
 
 
 
 
 
 
111
 
112
  return None
113
 
 
105
  import shutil
106
  shutil.copy(generated_path, destination)
107
 
108
+ # Dynamic URL Generation for Deployment
109
+ # If running on Hugging Face, SPACE_ID (e.g. "user/repo") is set.
110
+ space_id = os.getenv("SPACE_ID")
111
+ if space_id:
112
+ # HF Spaces use the format: https://user-repo.hf.space
113
+ host = space_id.replace("/", "-")
114
+ base_url = f"https://{host}.hf.space"
115
+ else:
116
+ # Localhost fallback
117
+ base_url = "http://localhost:8000"
118
+
119
+ final_url = f"{base_url}/static/{output_filename}"
120
+ print(f"✅ Generated Image URL: {final_url}")
121
+ return final_url
122
 
123
  return None
124