rapacious commited on
Commit
1ec8046
·
verified ·
1 Parent(s): 9f3a452

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -3
app.py CHANGED
@@ -56,12 +56,24 @@ async def generate_text(input: TextInput):
56
  async def root():
57
  return {"message": "Qwen2.5-0.5B API is running!"}
58
 
59
- # Endpoint hiển thị API URL
60
  @app.get("/api_link")
61
  async def get_api_link(request: Request):
 
62
  host = request.client.host
63
- return {"api_url": f"http://{host}:7860"}
 
 
 
 
 
 
 
 
 
 
 
64
 
65
  # Chạy server khi file được gọi trực tiếp
66
  if __name__ == "__main__":
67
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
56
  async def root():
57
  return {"message": "Qwen2.5-0.5B API is running!"}
58
 
59
+ # Endpoint hiển thị API URL đầy đủ
60
  @app.get("/api_link")
61
  async def get_api_link(request: Request):
62
+ # Lấy host từ request
63
  host = request.client.host
64
+ # Lấy port từ server (nếu chạy local thì mặc định là 7860)
65
+ port = request.url.port if request.url.port else 7860
66
+ # Tạo URL đầy đủ
67
+ base_url = f"http://{host}:{port}"
68
+ return {
69
+ "api_url": base_url,
70
+ "endpoints": {
71
+ "health_check": f"{base_url}/",
72
+ "generate_text": f"{base_url}/generate",
73
+ "api_link": f"{base_url}/api_link"
74
+ }
75
+ }
76
 
77
  # Chạy server khi file được gọi trực tiếp
78
  if __name__ == "__main__":
79
+ uvicorn.run(app, host="0.0.0.0", port=7860)