MeshMax commited on
Commit
49705d6
·
verified ·
1 Parent(s): b2321f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -22
app.py CHANGED
@@ -120,34 +120,40 @@ def compute_embedding(title, description, tags, thumbnail_url):
120
  fused = attn_out.squeeze(1)
121
  return fused.squeeze(0).cpu().numpy().tolist() # Note: This is proj_dim=768, not 1—adjust if regression output
122
 
123
- # --- FastAPI + Gradio (unchanged) ---
124
- app = FastAPI()
125
-
126
- @app.post("/api/get_embedding")
127
- async def api_get_embedding(request: Request):
128
- data = await request.json()
129
- emb = compute_embedding(
130
- data.get("title", ""), data.get("description", ""),
131
- data.get("tags", ""), data.get("thumbnail_url", "")
132
- )
133
- return JSONResponse({"embedding": emb})
134
 
 
135
  def gradio_fn(title, description, tags, thumbnail_url):
136
  emb = compute_embedding(title, description, tags, thumbnail_url)
137
- return f"Embedding length={len(emb)}; first 10: {emb[:10]}"
138
 
139
- gr_interface = gr.Interface(
 
140
  fn=gradio_fn,
141
- inputs=[gr.Textbox(label="Title"), gr.Textbox(label="Description"),
142
- gr.Textbox(label="Tags"), gr.Textbox(label="Thumbnail URL")],
143
- outputs="text",
 
 
 
 
144
  title="Video Embedding Generator",
145
- description="Generates fused multimodal embeddings from video metadata",
 
 
 
 
146
  )
147
 
148
- app = gr.mount_gradio_app(app, gr_interface, path="/")
149
-
150
- # NEW: Launch the server (blocks until shutdown)
151
  if __name__ == "__main__":
152
- import uvicorn
153
- uvicorn.run(app, host="0.0.0.0", port=7860, log_level="info")
 
 
 
 
 
 
 
 
120
  fused = attn_out.squeeze(1)
121
  return fused.squeeze(0).cpu().numpy().tolist() # Note: This is proj_dim=768, not 1—adjust if regression output
122
 
123
+ # --- Keep everything up to compute_embedding() unchanged ---
124
+ # (Imports, config, model loading, transform, compute_embedding)
 
 
 
 
 
 
 
 
 
125
 
126
+ # --- NEW: Pure Gradio Interface + Launch (remove FastAPI entirely) ---
127
  def gradio_fn(title, description, tags, thumbnail_url):
128
  emb = compute_embedding(title, description, tags, thumbnail_url)
129
+ return f"Embedding length={len(emb)}; first 10: {emb[:10]}\nFull embedding: {emb}"
130
 
131
+ # Create the interface (same as before)
132
+ demo = gr.Interface( # Renamed from gr_interface for clarity
133
  fn=gradio_fn,
134
+ inputs=[
135
+ gr.Textbox(label="Title", placeholder="Enter video title..."),
136
+ gr.Textbox(label="Description", placeholder="Enter video description..."),
137
+ gr.Textbox(label="Tags", placeholder="Enter comma-separated tags..."),
138
+ gr.Textbox(label="Thumbnail URL", placeholder="Enter image URL (e.g., https://example.com/thumb.jpg)...")
139
+ ],
140
+ outputs=gr.Textbox(label="Generated Embedding", lines=10),
141
  title="Video Embedding Generator",
142
+ description="Generates fused multimodal embeddings from video metadata using LaBSE + ViT + Custom Fusion.",
143
+ examples=[ # Optional: Add sample inputs for easy testing
144
+ ["Test Video", "A sample description.", "ml, ai, video", "https://via.placeholder.com/224"]
145
+ ],
146
+ allow_flagging="never" # Disable if not needed
147
  )
148
 
149
+ # NEW: Launch directly (blocks and serves everything)
 
 
150
  if __name__ == "__main__":
151
+ demo.queue(max_size=10) # Enable queuing for concurrency (HF handles 10+ users)
152
+ demo.launch(
153
+ server_name="0.0.0.0",
154
+ server_port=7860,
155
+ share=False, # HF provides public URL, no need for temp share
156
+ show_api=True, # Exposes /api endpoint automatically (see below)
157
+ debug=False, # Set True for more logs during testing
158
+ favicon_path=None # Optional: Add custom favicon later
159
+ )