Fdgg55 commited on
Commit
7e33cec
ยท
verified ยท
1 Parent(s): 97bd74b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -17
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from fastapi import FastAPI, UploadFile, File, HTTPException
2
- from fastapi.responses import Response
 
3
  import yt_dlp
4
  import whisper
5
  import tempfile
@@ -7,38 +8,101 @@ import os
7
  import io
8
  from diffusers import StableDiffusionPipeline
9
 
10
- app = FastAPI(title="Silent Tech Utils API")
 
 
 
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  print("Loading Whisper Voice AI...")
13
  voice_model = whisper.load_model("base")
14
 
15
  print("Loading Uncensored Image AI...")
16
- # safety_checker=None completely disables the NSFW and violence filters!
17
  image_model = StableDiffusionPipeline.from_pretrained("prompthero/openjourney", safety_checker=None)
18
  image_model.to("cpu")
19
 
20
- @app.get("/")
 
21
  def read_root():
22
- return {"status": "Silent Utils API is ONLINE"}
23
 
24
- @app.get("/api/download")
25
  def download_media(url: str):
26
  """Bypasses protections and gets the direct raw MP4/MP3 link."""
27
- ydl_opts = {'format': 'best', 'quiet': True, 'no_warnings': True, 'skip_download': True}
 
 
 
 
 
 
 
 
 
28
  try:
29
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
30
- info = ydl.extract_info(url, download=False)
 
 
 
 
 
 
 
 
 
 
 
 
31
  return {
32
  "success": True,
33
- "title": info.get('title'),
34
- "download_url": info.get('url') # The direct raw link!
35
  }
36
  except Exception as e:
37
  raise HTTPException(status_code=400, detail=str(e))
38
 
39
- @app.post("/api/transcribe")
40
  async def transcribe_audio(file: UploadFile = File(...)):
41
- """Converts WhatsApp voice notes to text."""
42
  try:
43
  with tempfile.NamedTemporaryFile(delete=False, suffix=".ogg") as temp_audio:
44
  temp_audio.write(await file.read())
@@ -50,18 +114,16 @@ async def transcribe_audio(file: UploadFile = File(...)):
50
  except Exception as e:
51
  raise HTTPException(status_code=500, detail=str(e))
52
 
53
- @app.get("/api/image")
54
  def generate_image(prompt: str):
55
  """Generates an uncensored image and returns it directly as a PNG."""
56
  try:
57
- # Generate the image (15 steps is faster for CPU)
58
- image = image_model(prompt, num_inference_steps=15).images[0]
59
 
60
- # Convert it to a raw PNG image file
61
  img_bytes = io.BytesIO()
62
  image.save(img_bytes, format="PNG")
63
 
64
- # Send the actual image picture directly to the bot, not just text!
65
  return Response(content=img_bytes.getvalue(), media_type="image/png")
66
  except Exception as e:
67
  raise HTTPException(status_code=500, detail=str(e))
 
1
  from fastapi import FastAPI, UploadFile, File, HTTPException
2
+ from fastapi.responses import Response, HTMLResponse
3
+ from fastapi.openapi.docs import get_swagger_ui_html
4
  import yt_dlp
5
  import whisper
6
  import tempfile
 
8
  import io
9
  from diffusers import StableDiffusionPipeline
10
 
11
+ # --- 1. BEAUTIFUL API METADATA ---
12
+ api_description = """
13
+ <div style="text-align: center; margin-top: 20px;">
14
+ <img src="https://i.ibb.co/C5nyyyXH/cccfe44a8d63663a60eed6f0300a8b44.jpg" width="150" style="border-radius: 15px; box-shadow: 0 4px 8px rgba(0,0,0,0.5);">
15
+ <h2>Welcome to the Silent Tech Utility Engine</h2>
16
+ </div>
17
 
18
+ This is the **Private Backend API** for the Silent Bot network.
19
+ It is completely independent, uncensored, and runs on a dedicated 16GB RAM Linux container.
20
+
21
+ ### ๐Ÿš€ Available Microservices
22
+ * **Media Downloader:** Bypass website protections to get direct MP4/MP3 links.
23
+ * **Voice AI:** Local voice-to-text transcription using OpenAI's Whisper.
24
+ * **Image Studio:** Uncensored Text-to-Image generation using Stable Diffusion.
25
+ """
26
+
27
+ tags_metadata = [
28
+ {"name": "System", "description": "Server health status."},
29
+ {"name": "Media Downloader", "description": "Extract raw media URLs from social platforms."},
30
+ {"name": "Voice AI", "description": "Transcribe audio files perfectly."},
31
+ {"name": "Image AI", "description": "Generate uncensored images."}
32
+ ]
33
+
34
+ app = FastAPI(
35
+ title="๐ŸŒŸ Silent Tech Private API",
36
+ description=api_description,
37
+ version="2.0.0",
38
+ openapi_tags=tags_metadata,
39
+ docs_url=None, # Disable the ugly default docs
40
+ redoc_url=None
41
+ )
42
+
43
+ # --- 2. DARK MODE CUSTOM DOCS ---
44
+ @app.get("/docs", include_in_schema=False)
45
+ async def custom_swagger_ui_html():
46
+ return get_swagger_ui_html(
47
+ openapi_url=app.openapi_url,
48
+ title="Silent Tech API - Docs",
49
+ swagger_favicon_url="https://i.ibb.co/C5nyyyXH/cccfe44a8d63663a60eed6f0300a8b44.jpg",
50
+ # Injecting a sleek hacker dark mode theme!
51
+ swagger_css_url="https://cdn.jsdelivr.net/gh/Itz-fork/Swagger-Dark-Theme@main/SwaggerDark.css"
52
+ )
53
+
54
+ # --- 3. LOAD AI MODELS ---
55
  print("Loading Whisper Voice AI...")
56
  voice_model = whisper.load_model("base")
57
 
58
  print("Loading Uncensored Image AI...")
 
59
  image_model = StableDiffusionPipeline.from_pretrained("prompthero/openjourney", safety_checker=None)
60
  image_model.to("cpu")
61
 
62
+ # --- 4. API ENDPOINTS ---
63
+ @app.get("/", tags=["System"])
64
  def read_root():
65
+ return {"status": "Silent Utils API is ONLINE", "version": "2.0.0"}
66
 
67
+ @app.get("/api/download", tags=["Media Downloader"])
68
  def download_media(url: str):
69
  """Bypasses protections and gets the direct raw MP4/MP3 link."""
70
+ clean_url = url.strip()
71
+
72
+ ydl_opts = {
73
+ 'format': 'best',
74
+ 'quiet': True,
75
+ 'no_warnings': True,
76
+ 'skip_download': True,
77
+ 'nocheckcertificate': True # Fixes strict SSL blocks
78
+ }
79
+
80
  try:
81
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
82
+ info = ydl.extract_info(clean_url, download=False)
83
+
84
+ # If the user accidentally links a playlist, grab the first video
85
+ if 'entries' in info:
86
+ info = info['entries'][0]
87
+
88
+ final_url = info.get('url')
89
+ if not final_url and 'requested_downloads' in info:
90
+ final_url = info['requested_downloads'][0].get('url')
91
+
92
+ if not final_url:
93
+ raise Exception("Could not extract the raw video URL.")
94
+
95
  return {
96
  "success": True,
97
+ "title": info.get('title', 'Silent Media'),
98
+ "download_url": final_url
99
  }
100
  except Exception as e:
101
  raise HTTPException(status_code=400, detail=str(e))
102
 
103
+ @app.post("/api/transcribe", tags=["Voice AI"])
104
  async def transcribe_audio(file: UploadFile = File(...)):
105
+ """Converts WhatsApp voice notes (or any audio) to text."""
106
  try:
107
  with tempfile.NamedTemporaryFile(delete=False, suffix=".ogg") as temp_audio:
108
  temp_audio.write(await file.read())
 
114
  except Exception as e:
115
  raise HTTPException(status_code=500, detail=str(e))
116
 
117
+ @app.get("/api/image", tags=["Image AI"])
118
  def generate_image(prompt: str):
119
  """Generates an uncensored image and returns it directly as a PNG."""
120
  try:
121
+ # Optimized for fast CPU generation
122
+ image = image_model(prompt, num_inference_steps=8, height=384, width=384).images[0]
123
 
 
124
  img_bytes = io.BytesIO()
125
  image.save(img_bytes, format="PNG")
126
 
 
127
  return Response(content=img_bytes.getvalue(), media_type="image/png")
128
  except Exception as e:
129
  raise HTTPException(status_code=500, detail=str(e))