Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,11 +4,11 @@ import gradio as gr
|
|
| 4 |
from fastmcp import FastMCP
|
| 5 |
from huggingface_hub import HfApi, model_info
|
| 6 |
|
| 7 |
-
#
|
| 8 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 9 |
hf_api = HfApi(token=HF_TOKEN) if HF_TOKEN else None
|
| 10 |
|
| 11 |
-
#
|
| 12 |
mcp = FastMCP("hf-tagging-bot")
|
| 13 |
|
| 14 |
@mcp.tool()
|
|
@@ -33,11 +33,10 @@ def get_current_tags(repo_id: str) -> str:
|
|
| 33 |
"error": str(e),
|
| 34 |
})
|
| 35 |
|
| 36 |
-
#
|
| 37 |
def gradio_tag_checker(repo_id):
|
| 38 |
return get_current_tags(repo_id)
|
| 39 |
|
| 40 |
-
# β Launch Gradio Interface β
|
| 41 |
demo = gr.Interface(
|
| 42 |
fn=gradio_tag_checker,
|
| 43 |
inputs=gr.Textbox(label="Enter HuggingFace Model Repo ID", placeholder="e.g. bert-base-uncased"),
|
|
@@ -46,12 +45,8 @@ demo = gr.Interface(
|
|
| 46 |
description="Uses FastMCP + HuggingFace Hub SDK to fetch current tags from any model repo."
|
| 47 |
)
|
| 48 |
|
| 49 |
-
#
|
| 50 |
if __name__ == "__main__":
|
| 51 |
import threading
|
| 52 |
-
|
| 53 |
-
# Run FastMCP in background thread
|
| 54 |
threading.Thread(target=mcp.run, daemon=True).start()
|
| 55 |
-
|
| 56 |
-
# Run Gradio UI
|
| 57 |
-
demo.launch()
|
|
|
|
| 4 |
from fastmcp import FastMCP
|
| 5 |
from huggingface_hub import HfApi, model_info
|
| 6 |
|
| 7 |
+
# Hugging Face token from Space secrets
|
| 8 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 9 |
hf_api = HfApi(token=HF_TOKEN) if HF_TOKEN else None
|
| 10 |
|
| 11 |
+
# FastMCP server setup
|
| 12 |
mcp = FastMCP("hf-tagging-bot")
|
| 13 |
|
| 14 |
@mcp.tool()
|
|
|
|
| 33 |
"error": str(e),
|
| 34 |
})
|
| 35 |
|
| 36 |
+
# Gradio UI wrapper
|
| 37 |
def gradio_tag_checker(repo_id):
|
| 38 |
return get_current_tags(repo_id)
|
| 39 |
|
|
|
|
| 40 |
demo = gr.Interface(
|
| 41 |
fn=gradio_tag_checker,
|
| 42 |
inputs=gr.Textbox(label="Enter HuggingFace Model Repo ID", placeholder="e.g. bert-base-uncased"),
|
|
|
|
| 45 |
description="Uses FastMCP + HuggingFace Hub SDK to fetch current tags from any model repo."
|
| 46 |
)
|
| 47 |
|
| 48 |
+
# Run both FastMCP and Gradio safely
|
| 49 |
if __name__ == "__main__":
|
| 50 |
import threading
|
|
|
|
|
|
|
| 51 |
threading.Thread(target=mcp.run, daemon=True).start()
|
| 52 |
+
demo.launch(quiet=True, show_error=False) # β
Prevent uvicorn logging crash
|
|
|
|
|
|