Fdgg55 commited on
Commit
32bd7de
ยท
verified ยท
1 Parent(s): 7e33cec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -27
app.py CHANGED
@@ -1,6 +1,5 @@
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,20 +7,17 @@ import os
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 = [
@@ -32,24 +28,81 @@ tags_metadata = [
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...")
@@ -59,6 +112,7 @@ 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():
@@ -74,14 +128,13 @@ def download_media(url: str):
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
 
@@ -118,7 +171,6 @@ async def transcribe_audio(file: UploadFile = File(...)):
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()
 
1
  from fastapi import FastAPI, UploadFile, File, HTTPException
2
  from fastapi.responses import Response, HTMLResponse
 
3
  import yt_dlp
4
  import whisper
5
  import tempfile
 
7
  import io
8
  from diffusers import StableDiffusionPipeline
9
 
10
+ # --- 1. METADATA ---
11
  api_description = """
12
+ <div style="text-align: center; margin-top: 20px; border-bottom: 1px solid #333; padding-bottom: 20px;">
13
+ <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;">
14
+ <h2 style="color: #00ffcc; text-shadow: 0 0 10px #00ffcc; margin-top: 15px; font-family: monospace;">SILENT TECH UTILITY ENGINE</h2>
15
+ </div>
16
+ <br>
17
+ <div style="color: #a0aec0; font-size: 15px; text-align: center;">
18
+ This is the <b>Private Backend API</b> for the Silent Bot network.<br>
19
+ Completely independent, uncensored, and running on a dedicated 16GB RAM Linux container.
20
  </div>
 
 
 
 
 
 
 
 
21
  """
22
 
23
  tags_metadata = [
 
28
  ]
29
 
30
  app = FastAPI(
31
+ title="SILENT TECH API",
32
  description=api_description,
33
  version="2.0.0",
34
  openapi_tags=tags_metadata,
35
+ docs_url=None, # We disable the default so we can use our custom Neon UI
36
  redoc_url=None
37
  )
38
 
39
+ # --- 2. CUSTOM NEON UI ---
40
  @app.get("/docs", include_in_schema=False)
41
+ async def neon_swagger_ui():
42
+ html = """
43
+ <!DOCTYPE html>
44
+ <html lang="en">
45
+ <head>
46
+ <meta charset="UTF-8">
47
+ <title>Silent Tech API - NEON UI</title>
48
+ <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui.css" />
49
+ <link rel="icon" type="image/png" href="https://i.ibb.co/C5nyyyXH/cccfe44a8d63663a60eed6f0300a8b44.jpg" />
50
+ <style>
51
+ /* ๐Ÿš€ CUSTOM NEON CYBERPUNK CSS ๐Ÿš€ */
52
+ body { background-color: #050505 !important; color: #00ffcc !important; font-family: 'Segoe UI', Tahoma, sans-serif; }
53
+ .swagger-ui .info .title { color: #00ffcc !important; text-shadow: 0 0 10px rgba(0, 255, 204, 0.7); }
54
+ .swagger-ui .info p { color: #a0aec0 !important; }
55
+ .swagger-ui .info h1, .swagger-ui .info h2, .swagger-ui .info h3, .swagger-ui .info h4, .swagger-ui .info h5 { color: #00ffcc !important; }
56
+ .swagger-ui .info a { color: #bd00ff !important; text-shadow: 0 0 8px rgba(189, 0, 255, 0.7); }
57
+ .swagger-ui .scheme-container { background-color: #0a0a0a !important; box-shadow: 0 0 15px rgba(0, 255, 204, 0.1); border-bottom: 1px solid #00ffcc; }
58
+
59
+ /* GET Requests (Neon Cyan) */
60
+ .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; }
61
+ .swagger-ui .opblock.opblock-get .opblock-summary-method { background: #00ffcc !important; color: #000 !important; font-weight: bold; }
62
+
63
+ /* POST Requests (Neon Purple) */
64
+ .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; }
65
+ .swagger-ui .opblock.opblock-post .opblock-summary-method { background: #bd00ff !important; color: #fff !important; font-weight: bold; }
66
+
67
+ /* Glowing Execute Button */
68
+ .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; }
69
+ .swagger-ui .btn.execute:hover { box-shadow: 0 0 25px rgba(0, 255, 204, 1) !important; }
70
+ .swagger-ui .btn { color: #00ffcc !important; border-color: #00ffcc !important; }
71
+
72
+ /* Text & Inputs */
73
+ .swagger-ui .opblock-body pre.microlight { background-color: #000 !important; border: 1px solid #333 !important; border-radius: 8px; color: #fff !important; }
74
+ .swagger-ui .parameters-col_name { color: #bd00ff !important; }
75
+ .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; }
76
+ .swagger-ui .responses-inner h4, .swagger-ui .responses-inner h5 { color: #00ffcc !important; }
77
+ .swagger-ui svg { fill: #00ffcc !important; }
78
+
79
+ /* Models Section */
80
+ .swagger-ui section.models { border: 1px solid #333 !important; background: #0a0a0a !important; border-radius: 8px;}
81
+ .swagger-ui section.models h4 { color: #00ffcc !important; border-bottom: 1px solid #333; }
82
+ .swagger-ui .model-title { color: #bd00ff !important; }
83
+ .swagger-ui .model { color: #a0aec0 !important; }
84
+ </style>
85
+ </head>
86
+ <body>
87
+ <div id="swagger-ui"></div>
88
+ <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-bundle.js"></script>
89
+ <script src="https://cdn.jsdelivr.net/npm/swagger-ui-dist@5/swagger-ui-standalone-preset.js"></script>
90
+ <script>
91
+ window.onload = function() {
92
+ window.ui = SwaggerUIBundle({
93
+ url: "/openapi.json",
94
+ dom_id: '#swagger-ui',
95
+ deepLinking: true,
96
+ presets: [ SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset ],
97
+ layout: "BaseLayout"
98
+ });
99
+ };
100
+ </script>
101
+ </body>
102
+ </html>
103
+ """
104
+ return HTMLResponse(html)
105
+
106
 
107
  # --- 3. LOAD AI MODELS ---
108
  print("Loading Whisper Voice AI...")
 
112
  image_model = StableDiffusionPipeline.from_pretrained("prompthero/openjourney", safety_checker=None)
113
  image_model.to("cpu")
114
 
115
+
116
  # --- 4. API ENDPOINTS ---
117
  @app.get("/", tags=["System"])
118
  def read_root():
 
128
  'quiet': True,
129
  'no_warnings': True,
130
  'skip_download': True,
131
+ 'nocheckcertificate': True
132
  }
133
 
134
  try:
135
  with yt_dlp.YoutubeDL(ydl_opts) as ydl:
136
  info = ydl.extract_info(clean_url, download=False)
137
 
 
138
  if 'entries' in info:
139
  info = info['entries'][0]
140
 
 
171
  def generate_image(prompt: str):
172
  """Generates an uncensored image and returns it directly as a PNG."""
173
  try:
 
174
  image = image_model(prompt, num_inference_steps=8, height=384, width=384).images[0]
175
 
176
  img_bytes = io.BytesIO()