Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,52 +1,32 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import json
|
| 3 |
import gradio as gr
|
| 4 |
-
|
| 5 |
-
from
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 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 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
"count": len(current_tags),
|
| 28 |
-
})
|
| 29 |
except Exception as e:
|
| 30 |
-
return
|
| 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=
|
| 42 |
-
inputs=
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
-
# Run both FastMCP and Gradio safely
|
| 49 |
if __name__ == "__main__":
|
| 50 |
-
|
| 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()
|
|
|
|
|
|