from flask import Flask, render_template from flask_socketio import SocketIO from PIL import Image, ImageDraw, ImageFont import requests import ffmpeg from io import BytesIO app = Flask(__name__) socketio = SocketIO(app, cors_allowed_origins="*") # Function to create TV display def create_tv_display(ai_text="Waiting...", video_thumbnail=None, waifu_url=None): img = Image.new("RGB", (1600, 800), "black") draw = ImageDraw.Draw(img) # Load Font try: font = ImageFont.truetype("arial.ttf", 30) except: font = ImageFont.load_default() # Monitor Positions left_tv = (50, 150, 450, 650) # AI Chat center_tv = (500, 100, 1100, 700) # Video right_tv = (1150, 150, 1550, 650) # Waifu draw.rectangle(left_tv, outline="gray", width=5) draw.rectangle(center_tv, outline="gray", width=5) draw.rectangle(right_tv, outline="gray", width=5) # AI Response (Left TV) draw.text((70, 300), ai_text, fill="white", font=font) # Video Thumbnail (Center TV) if video_thumbnail: try: video_img = Image.open(BytesIO(requests.get(video_thumbnail).content)) video_img = video_img.resize((600, 600)) img.paste(video_img, (500, 100)) except Exception as e: print("Error loading video image:", e) # Waifu Image (Right TV) if waifu_url: try: waifu_img = Image.open(BytesIO(requests.get(waifu_url).content)) waifu_img = waifu_img.resize((400, 500)) img.paste(waifu_img, (1150, 150)) except Exception as e: print("Error loading waifu image:", e) img.save("static/tv_display.png") # Function to process AI response def fetch_ai_response(command): try: response = requests.get(f"https://apis.davidcyriltech.my.id/ai/pixtral?text={command}") data = response.json() return data["response"] if data["success"] else "AI Error" except: return "API Error" # Function to fetch video def fetch_video(query): try: response = requests.get(f"https://apis.davidcyriltech.my.id/play?query={query}") data = response.json() if data["status"]: return data["result"]["thumbnail"], data["result"]["download_url"] except: return None, None return None, None # Function to fetch waifu def fetch_waifu(): try: response = requests.get("https://reaperxxxx-anime.hf.space/api/waifu?category=waifu") data = response.json() return data["image_url"] if "image_url" in data else None except: return None # Handle Commands @socketio.on("send_command") def handle_command(data): command = data["command"] if command.startswith(".play"): query = command.replace(".play ", "") thumbnail, video_url = fetch_video(query) create_tv_display("Playing: " + query, video_thumbnail=thumbnail) socketio.emit("update_screen", {"image": "static/tv_display.png", "video": video_url}) elif command.startswith(".waifu"): waifu_url = fetch_waifu() create_tv_display("Here's your waifu!", waifu_url=waifu_url) socketio.emit("update_screen", {"image": "static/tv_display.png"}) else: ai_response = fetch_ai_response(command) create_tv_display(ai_response) socketio.emit("update_screen", {"image": "static/tv_display.png"}) # Home Route @app.route("/") def home(): return render_template("index.html") if __name__ == "__main__": create_tv_display() # Initialize display socketio.run(app, host="0.0.0.0", port=7860, debug=True)