ACCC1380 commited on
Commit
173ab15
1 Parent(s): 45810a0

Create a.py

Browse files
Files changed (1) hide show
  1. a.py +72 -0
a.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template_string
2
+ from flask import Flask, send_file, abort
3
+ import os
4
+ import random
5
+ app = Flask(__name__)
6
+
7
+ @app.route('/flux')
8
+ def home():
9
+ # 将 iframe 嵌入到页面
10
+ embedded_url = "https://s5k.cn/inner/studio/gradio?backend_url=/api/v1/studio/muse/flux_dev/gradio/&sdk_version=4.38.1&t=1723609688306&__theme=light&studio_token=c032a664-302c-4509-986b-e2e17d5ab148"
11
+ return render_template_string('''
12
+ <!DOCTYPE html>
13
+ <html lang="en">
14
+ <head>
15
+ <meta charset="UTF-8">
16
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
17
+ <title>FLUX.dev 作者:正在加载</title>
18
+ <style>
19
+ body, html {
20
+ margin: 0;
21
+ padding: 0;
22
+ height: 100%;
23
+ overflow: hidden;
24
+ }
25
+ iframe {
26
+ position: absolute;
27
+ top: 0;
28
+ left: 0;
29
+ width: 100%;
30
+ height: 100%;
31
+ border: none;
32
+ }
33
+ </style>
34
+ </head>
35
+ <body>
36
+ <iframe src="{{ embedded_url }}" allow="camera; microphone; fullscreen"></iframe>
37
+ </body>
38
+ </html>
39
+ ''', embedded_url=embedded_url)
40
+
41
+ @app.route('/')
42
+ def display_random_image():
43
+ img_directory = '/root/rurudo'
44
+ # 获取目录中的所有文件
45
+ files = os.listdir(img_directory)
46
+
47
+ # 过滤掉非图片文件
48
+ image_files = [f for f in files if f.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp'))]
49
+
50
+ if not image_files:
51
+ abort(404, description="No images found in the directory")
52
+
53
+ # 随机选择一张图片
54
+ selected_image = random.choice(image_files)
55
+
56
+ # 完整路径
57
+ image_path = os.path.join(img_directory, selected_image)
58
+
59
+ # 根据文件扩展名确定 MIME 类型
60
+ mime_type = None
61
+ if selected_image.lower().endswith('.png'):
62
+ mime_type = 'image/png'
63
+ elif selected_image.lower().endswith('.jpg') or selected_image.lower().endswith('.jpeg'):
64
+ mime_type = 'image/jpeg'
65
+ elif selected_image.lower().endswith('.gif'):
66
+ mime_type = 'image/gif'
67
+ elif selected_image.lower().endswith('.bmp'):
68
+ mime_type = 'image/bmp'
69
+
70
+ return send_file(image_path, mimetype=mime_type)
71
+ if __name__ == '__main__':
72
+ app.run(host='0.0.0.0', port=31000, debug=False)