apple muncy commited on
Commit
3553c20
·
1 Parent(s): ff26013

Add dashboard beginning code

Browse files

Signed-off-by: apple muncy <[email protected]>

Files changed (1) hide show
  1. app.py +25 -7
app.py CHANGED
@@ -28,6 +28,10 @@ HF_MODEL = os.getenv("HF_MODEL", "Qwen/Qwen2.5-72B-Instruct")
28
  DEFAULT_PROVIDER: Literal["hf-inference"] = "hf-inference"
29
  HF_PROVIDER = os.getenv("HF_PROVIDER", DEFAULT_PROVIDER)
30
 
 
 
 
 
31
  # Simple storage for processed tag operations
32
  tag_operations_store: List[Dict[str, Any]] = []
33
 
@@ -82,8 +86,8 @@ class WebhookEvent(BaseModel):
82
  repo: Dict[str, str]
83
 
84
 
85
- app = FastAPI(title="HF Tagging Bot")
86
- app.add_middleware(CORSMiddleware, allow_origins=["*"])
87
 
88
 
89
  async def get_agent():
@@ -118,10 +122,11 @@ async def get_agent():
118
  await agent_instance.load_tools()
119
  logger.info("Tools loaded successfully")
120
 
121
- print(f"\033[1;38;5;11mAgent loaded with {len(agent_instance.available_tools)} tools:\033[0;0m")
 
122
  for t in agent_instance.available_tools:
123
- print(f"\033[1;38;5;11m {t.function.name}\033[0;0m")
124
-
125
 
126
  except Exception as e:
127
  print(f"❌ Error creating/loading agent: {str(e)}")
@@ -394,7 +399,7 @@ Please process all {len(all_tags)} tags: {", ".join(all_tags)}
394
  return error_msg
395
 
396
 
397
- @app.post("/webhook")
398
  async def webhook_handler(request: Request, background_tasks: BackgroundTasks):
399
  """Handle HF Hub webhooks"""
400
  webhook_secret = request.headers.get("X-Webhook-Secret")
@@ -521,11 +526,24 @@ def create_gradio_app():
521
  """)
522
 
523
  return demo
 
 
 
 
 
 
 
 
 
524
 
525
 
526
  # Mount Gradio app
527
  gradio_app = create_gradio_app()
528
- app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
 
 
 
 
529
 
530
 
531
  if __name__ == "__main__":
 
28
  DEFAULT_PROVIDER: Literal["hf-inference"] = "hf-inference"
29
  HF_PROVIDER = os.getenv("HF_PROVIDER", DEFAULT_PROVIDER)
30
 
31
+ #global variables to make data avalable to gradio blocks
32
+ g_tools = []
33
+
34
+
35
  # Simple storage for processed tag operations
36
  tag_operations_store: List[Dict[str, Any]] = []
37
 
 
86
  repo: Dict[str, str]
87
 
88
 
89
+ my_app = FastAPI(title="HF Tagging Bot")
90
+ my_app.add_middleware(CORSMiddleware, allow_origins=["*"])
91
 
92
 
93
  async def get_agent():
 
122
  await agent_instance.load_tools()
123
  logger.info("Tools loaded successfully")
124
 
125
+ print(f"Agent loaded with {len(agent_instance.available_tools)} tools:")
126
+ Glocal g_tools
127
  for t in agent_instance.available_tools:
128
+ print(f"🔧🔧• {t.function.name}")
129
+ g_tools.append(t.function.name)
130
 
131
  except Exception as e:
132
  print(f"❌ Error creating/loading agent: {str(e)}")
 
399
  return error_msg
400
 
401
 
402
+ @my_app.post("/webhook")
403
  async def webhook_handler(request: Request, background_tasks: BackgroundTasks):
404
  """Handle HF Hub webhooks"""
405
  webhook_secret = request.headers.get("X-Webhook-Secret")
 
526
  """)
527
 
528
  return demo
529
+ #create dashboard interface
530
+ def create_dash_app():
531
+ """Create Gradio interface"""
532
+ with gr.Blocks(title="HF Tagging Bot", theme=gr.themes.Soft()) as demo:
533
+ gr.Markdown("# 🏷️ HF Tagging Bot Dashboard")
534
+ gr.Markdown("*Tools found*")
535
+
536
+
537
+ return demo
538
 
539
 
540
  # Mount Gradio app
541
  gradio_app = create_gradio_app()
542
+ app_gradio = gr.mount_gradio_app(my_app, gradio_app, path="/gradio")
543
+
544
+ dash_app = create_dash_app()
545
+ app_dash =gr.mount_gradio_app(my_app, dash_app, path="/dashboard")
546
+
547
 
548
 
549
  if __name__ == "__main__":