Juna190825 commited on
Commit
6f16573
·
verified ·
1 Parent(s): d0c5706

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -7,6 +7,24 @@ from tensorflow.keras.models import load_model
7
  from tensorflow.keras.preprocessing.sequence import pad_sequences
8
  from huggingface_hub import hf_hub_download
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  np.random.seed(42)
11
  tf.random.set_seed(42)
12
 
@@ -73,4 +91,11 @@ with gr.Blocks() as demo:
73
 
74
  gr.Examples(["What is your name?", "I love chocolate.", "Where is the nearest station?"], inputs=input_text)
75
 
 
 
 
 
 
 
 
76
  demo.launch()
 
7
  from tensorflow.keras.preprocessing.sequence import pad_sequences
8
  from huggingface_hub import hf_hub_download
9
 
10
+ from fastapi import FastAPI, Request
11
+ import uvicorn
12
+ import threading
13
+
14
+ app = FastAPI()
15
+
16
+ @app.post("/reload")
17
+ async def reload_model(request: Request):
18
+ token = request.headers.get("x-hub-token")
19
+ if token != "mi-secret-token":
20
+ print("🚫 Unauthorized webhook request.")
21
+ return {"status": "unauthorized"}
22
+
23
+ load_latest_model()
24
+ print("🔁 Model reloaded securely via webhook.")
25
+ return {"status": "ok"}
26
+
27
+
28
  np.random.seed(42)
29
  tf.random.set_seed(42)
30
 
 
91
 
92
  gr.Examples(["What is your name?", "I love chocolate.", "Where is the nearest station?"], inputs=input_text)
93
 
94
+
95
+ def run_api():
96
+ uvicorn.run(app, host="0.0.0.0", port=7861)
97
+
98
+ threading.Thread(target=run_api, daemon=True).start()
99
+
100
+
101
  demo.launch()