rkservers commited on
Commit
1ec0bf0
·
verified ·
1 Parent(s): afabce3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, send_file
2
+ from PIL import Image, ImageDraw, ImageFont
3
+ import requests
4
+ from io import BytesIO
5
+
6
+ app = Flask(__name__)
7
+
8
+ # Function to create the TV setup image
9
+ def create_tv_display(text="Waiting for input..."):
10
+ # Load or create a blank image
11
+ img = Image.new("RGB", (1200, 600), "black")
12
+ draw = ImageDraw.Draw(img)
13
+
14
+ # Load font (make sure arial.ttf or any .ttf file is available)
15
+ try:
16
+ font = ImageFont.truetype("arial.ttf", 30)
17
+ except:
18
+ font = ImageFont.load_default()
19
+
20
+ # TV screen coordinates (left, center, right)
21
+ tv_positions = [(50, 150, 350, 450), (425, 100, 775, 500), (850, 150, 1150, 450)]
22
+
23
+ # Draw TV borders
24
+ for pos in tv_positions:
25
+ draw.rectangle(pos, outline="gray", width=5)
26
+
27
+ # Add text on the center TV
28
+ text_x, text_y = 510, 250
29
+ draw.text((text_x, text_y), text, fill="white", font=font, anchor="mm")
30
+
31
+ # Save the initial image
32
+ img.save("tv_display.png")
33
+ return img
34
+
35
+ # Function to fetch a waifu image and place it on the right TV
36
+ def fetch_waifu():
37
+ url = "https://reaperxxxx-anime.hf.space/api/waifu?category=waifu"
38
+ response = requests.get(url)
39
+ data = response.json()
40
+
41
+ if "image_url" in data:
42
+ # Open the base TV setup image
43
+ base_img = create_tv_display("Waifu Loading...")
44
+
45
+ # Fetch waifu image
46
+ waifu_img = Image.open(BytesIO(requests.get(data["image_url"]).content))
47
+
48
+ # Resize and paste onto the right TV screen area
49
+ waifu_img = waifu_img.resize((300, 300))
50
+ base_img.paste(waifu_img, (850, 150))
51
+
52
+ base_img.save("tv_display.png")
53
+ return "tv_display.png"
54
+
55
+ return None
56
+
57
+ # Flask Route to Process Commands
58
+ @app.route("/process", methods=["GET"])
59
+ def process_command():
60
+ command = request.args.get("cmd", "")
61
+
62
+ if command.startswith(".waifu"):
63
+ waifu_path = fetch_waifu()
64
+ return send_file(waifu_path, mimetype="image/png") if waifu_path else "Failed to load waifu"
65
+
66
+ else:
67
+ text_img = create_tv_display(command)
68
+ return send_file("tv_display.png", mimetype="image/png")
69
+
70
+ if __name__ == "__main__":
71
+ app.run(debug=True, port=7860)