ghosthets commited on
Commit
76ac794
·
verified ·
1 Parent(s): 9a7281b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -42
app.py CHANGED
@@ -1,52 +1,32 @@
1
- import os
2
- import json
3
  import gradio as gr
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()
15
- def get_current_tags(repo_id: str) -> str:
16
- """Get current tags from a HuggingFace model repository"""
17
- if not hf_api:
18
- return json.dumps({"error": "HF token not configured"})
19
 
 
20
  try:
21
- info = model_info(repo_id=repo_id, token=HF_TOKEN)
22
- current_tags = info.tags if info.tags else []
23
- return json.dumps({
24
- "status": "success",
25
- "repo_id": repo_id,
26
- "current_tags": current_tags,
27
- "count": len(current_tags),
28
- })
29
  except Exception as e:
30
- return json.dumps({
31
- "status": "error",
32
- "repo_id": repo_id,
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"),
43
- outputs=gr.Textbox(label="Current Tags (JSON)"),
44
- title="🔖 HuggingFace Tag Checker",
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
 
 
 
1
  import gradio as gr
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
+ from transformers import pipeline
5
 
6
+ # Load Mixtral model (via Transformers pipeline)
7
+ refiner = pipeline("text2text-generation", model="mistralai/Mixtral-8x7B-Instruct-v0.1")
 
 
 
 
 
 
 
 
 
 
8
 
9
+ def refine_from_url(url, instruction):
10
  try:
11
+ response = requests.get(url, timeout=5)
12
+ soup = BeautifulSoup(response.text, "html.parser")
13
+ raw_text = soup.get_text(separator="\n")
14
+ prompt = f"{instruction}\n\n{raw_text[:4000]}" # truncate for token limit
15
+ output = refiner(prompt, max_new_tokens=512)[0]["generated_text"]
16
+ return output
 
 
17
  except Exception as e:
18
+ return f"Error: {str(e)}"
 
 
 
 
 
 
 
 
19
 
20
  demo = gr.Interface(
21
+ fn=refine_from_url,
22
+ inputs=[
23
+ gr.Textbox(label="Enter URL"),
24
+ gr.Textbox(label="Refinement Instruction", placeholder="e.g. Clean and structure this for AI training")
25
+ ],
26
+ outputs=gr.Textbox(label="Refined Output"),
27
+ title="🔍 Data Refiner with Mixtral",
28
+ description="Crawl any webpage and refine its content using Mixtral 8x7B for AI training or research."
29
  )
30
 
 
31
  if __name__ == "__main__":
32
+ demo.launch()