Spaces:
Runtime error
Runtime error
File size: 9,046 Bytes
888df7c 7e33cec 888df7c 38b15f7 2373b18 38b15f7 888df7c 2373b18 7e33cec 32bd7de 7e33cec 32bd7de 7e33cec 2373b18 7e33cec 32bd7de 2373b18 38b15f7 888df7c 2373b18 7e33cec 888df7c 7e33cec 888df7c 7e33cec 888df7c 7e33cec 2373b18 7e33cec 32bd7de 7e33cec 888df7c 7e33cec 888df7c 7e33cec 888df7c 7e33cec 888df7c 7e33cec 888df7c 38b15f7 888df7c 38b15f7 7e33cec 38b15f7 7e33cec 38b15f7 888df7c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | from fastapi import FastAPI, UploadFile, File, HTTPException
from fastapi.responses import Response, HTMLResponse
import yt_dlp
import whisper
import tempfile
import os
import io
import urllib.request
import urllib.parse
import json
from diffusers import StableDiffusionPipeline
# --- 1. METADATA & NEON UI ---
api_description = """
<div style="text-align: center; margin-top: 20px; border-bottom: 1px solid #333; padding-bottom: 20px;">
<img src="https://i.ibb.co/C5nyyyXH/cccfe44a8d63663a60eed6f0300a8b44.jpg" width="150" style="border-radius: 15px; box-shadow: 0 0 20px rgba(0, 255, 204, 0.6); border: 2px solid #00ffcc;">
<h2 style="color: #00ffcc; text-shadow: 0 0 10px #00ffcc; margin-top: 15px; font-family: monospace;">SILENT TECH UTILITY ENGINE</h2>
</div>
<br>
<div style="color: #a0aec0; font-size: 15px; text-align: center;">
This is the <b>Private Backend API</b> for the Silent Bot network.<br>
Completely independent, uncensored, and running on a dedicated 16GB RAM Linux container.
</div>
"""
tags_metadata = [
{"name": "System", "description": "Server health status."},
{"name": "Media Downloader", "description": "Extract raw media URLs from social platforms."},
{"name": "Voice AI", "description": "Transcribe audio files perfectly."},
{"name": "Image AI", "description": "Generate uncensored images."}
]
app = FastAPI(
title="SILENT TECH API",
description=api_description,
version="2.0.0",
openapi_tags=tags_metadata,
docs_url=None,
redoc_url=None
)
@app.get("/docs", include_in_schema=False)
async def neon_swagger_ui():
html = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Silent Tech API - NEON UI</title>
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css" />
<link rel="icon" type="image/png" href="https://i.ibb.co/C5nyyyXH/cccfe44a8d63663a60eed6f0300a8b44.jpg" />
<style>
body { background-color: #050505 !important; color: #00ffcc !important; font-family: 'Segoe UI', Tahoma, sans-serif; }
.swagger-ui .info .title { color: #00ffcc !important; text-shadow: 0 0 10px rgba(0, 255, 204, 0.7); }
.swagger-ui .info p { color: #a0aec0 !important; }
.swagger-ui .info h1, .swagger-ui .info h2, .swagger-ui .info h3, .swagger-ui .info h4, .swagger-ui .info h5 { color: #00ffcc !important; }
.swagger-ui .info a { color: #bd00ff !important; text-shadow: 0 0 8px rgba(189, 0, 255, 0.7); }
.swagger-ui .scheme-container { background-color: #0a0a0a !important; box-shadow: 0 0 15px rgba(0, 255, 204, 0.1); border-bottom: 1px solid #00ffcc; }
.swagger-ui .opblock.opblock-get { background: rgba(0, 255, 204, 0.05) !important; border: 1px solid #00ffcc !important; box-shadow: 0 0 10px rgba(0, 255, 204, 0.2); border-radius: 8px; }
.swagger-ui .opblock.opblock-get .opblock-summary-method { background: #00ffcc !important; color: #000 !important; font-weight: bold; }
.swagger-ui .opblock.opblock-post { background: rgba(189, 0, 255, 0.05) !important; border: 1px solid #bd00ff !important; box-shadow: 0 0 10px rgba(189, 0, 255, 0.2); border-radius: 8px; }
.swagger-ui .opblock.opblock-post .opblock-summary-method { background: #bd00ff !important; color: #fff !important; font-weight: bold; }
.swagger-ui .btn.execute { background-color: #00ffcc !important; color: #000 !important; border: none !important; box-shadow: 0 0 15px rgba(0, 255, 204, 0.6) !important; font-weight: bold; transition: 0.3s; }
.swagger-ui .btn.execute:hover { box-shadow: 0 0 25px rgba(0, 255, 204, 1) !important; }
.swagger-ui .btn { color: #00ffcc !important; border-color: #00ffcc !important; }
.swagger-ui .opblock-body pre.microlight { background-color: #000 !important; border: 1px solid #333 !important; border-radius: 8px; color: #fff !important; }
.swagger-ui input[type=text], .swagger-ui input[type=file] { background: #000 !important; color: #00ffcc !important; border: 1px solid #bd00ff !important; border-radius: 4px; padding: 5px; }
.swagger-ui .responses-inner h4, .swagger-ui .responses-inner h5 { color: #00ffcc !important; }
.swagger-ui svg { fill: #00ffcc !important; }
.swagger-ui section.models { border: 1px solid #333 !important; background: #0a0a0a !important; border-radius: 8px;}
.swagger-ui section.models h4 { color: #00ffcc !important; border-bottom: 1px solid #333; }
</style>
</head>
<body>
<div id="swagger-ui"></div>
<script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
<script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-standalone-preset.js"></script>
<script>
window.onload = function() {
window.ui = SwaggerUIBundle({
url: "/openapi.json",
dom_id: '#swagger-ui',
deepLinking: true,
presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ],
layout: "BaseLayout"
});
};
</script>
</body>
</html>
"""
return HTMLResponse(html)
# --- 2. LOAD AI MODELS ---
print("Loading Whisper Voice AI...")
voice_model = whisper.load_model("base")
print("Loading Uncensored Image AI...")
image_model = StableDiffusionPipeline.from_pretrained("prompthero/openjourney", safety_checker=None)
image_model.to("cpu")
# --- 3. API ENDPOINTS ---
@app.get("/", tags=["System"])
def read_root():
return {"status": "Silent Utils API is ONLINE", "version": "2.0.0"}
@app.get("/api/download", tags=["Media Downloader"])
def download_media(url: str):
"""Bypasses protections and gets the direct raw MP4/MP3 link."""
clean_url = url.strip()
# 💥 FIREWALL BYPASS: If it's YouTube, route it through an external proxy API!
if "youtube.com" in clean_url or "youtu.be" in clean_url:
try:
bypass_url = f"https://api.bk9.site/yt/mp4?url={urllib.parse.quote(clean_url)}"
req = urllib.request.Request(bypass_url, headers={'User-Agent': 'Mozilla/5.0'})
with urllib.request.urlopen(req) as response:
data = json.loads(response.read().decode())
if data.get("status") and "BK9" in data:
return {
"success": True,
"title": data["BK9"].get("title", "YouTube Video"),
"download_url": data["BK9"].get("url")
}
except Exception as bypass_e:
print("Bypass failed:", str(bypass_e))
# If bypass fails, fall back to yt-dlp just in case
# Standard yt-dlp for TikTok, Instagram, Twitter, etc.
ydl_opts = {
'format': 'best',
'quiet': True,
'no_warnings': True,
'skip_download': True,
'nocheckcertificate': True
}
try:
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
info = ydl.extract_info(clean_url, download=False)
if 'entries' in info:
info = info['entries'][0]
final_url = info.get('url')
if not final_url and 'requested_downloads' in info:
final_url = info['requested_downloads'][0].get('url')
if not final_url:
raise Exception("Could not extract the raw video URL.")
return {
"success": True,
"title": info.get('title', 'Silent Media'),
"download_url": final_url
}
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
@app.post("/api/transcribe", tags=["Voice AI"])
async def transcribe_audio(file: UploadFile = File(...)):
"""Converts WhatsApp voice notes (or any audio) to text."""
try:
with tempfile.NamedTemporaryFile(delete=False, suffix=".ogg") as temp_audio:
temp_audio.write(await file.read())
temp_audio_path = temp_audio.name
result = voice_model.transcribe(temp_audio_path)
os.remove(temp_audio_path)
return {"success": True, "text": result["text"].strip()}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@app.get("/api/image", tags=["Image AI"])
def generate_image(prompt: str):
"""Generates an uncensored image and returns it directly as a PNG."""
try:
image = image_model(prompt, num_inference_steps=8, height=384, width=384).images[0]
img_bytes = io.BytesIO()
image.save(img_bytes, format="PNG")
return Response(content=img_bytes.getvalue(), media_type="image/png")
except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) |