Choose12 commited on
Commit
0f68ea5
·
verified ·
1 Parent(s): 868dd7f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +83 -94
index.html CHANGED
@@ -1,18 +1,15 @@
1
  <!DOCTYPE html>
2
- <html lang="ru" translate="no">
3
  <head>
4
  <meta charset="utf-8">
5
  <meta name="google" content="notranslate">
6
 
7
- <script type="module"
8
- src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js">
9
- </script>
10
 
11
- <link rel="stylesheet"
12
- href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css">
13
  </head>
14
 
15
- <body>
16
 
17
  <gradio-app>
18
 
@@ -23,146 +20,138 @@ import json
23
  from js import fetch
24
 
25
 
26
- # =========================
27
- # ГЕНЕРАЦИЯ
28
- # =========================
29
-
30
- async def generate(prompt):
31
 
32
  if not prompt:
33
- return None, "Введите идею!"
34
 
35
  try:
36
 
37
- r = await fetch(
38
  "https://mrfakename-z-image-turbo.hf.space/call/predict",
39
  method="POST",
40
- headers={"Content-Type": "application/json"},
41
- body=json.dumps({"data": [prompt]})
 
 
 
 
42
  )
43
 
44
- data = await r.json()
45
- event_id = data.get("event_id")
46
 
47
- if not event_id:
48
- return None, "Ошибка запуска генерации"
49
 
50
- r2 = await fetch(
51
- "https://mrfakename-z-image-turbo.hf.space/call/predict/"
52
- + event_id
53
  )
54
 
55
- text = await r2.text()
56
 
57
- for line in text.split("\n"):
58
 
59
  if line.startswith("data:"):
60
 
61
- try:
62
-
63
- result = json.loads(line[5:])
64
-
65
- url = result[0][0]["url"]
66
 
67
- return url, "✅ Готово!"
 
 
 
68
 
69
- except:
70
- pass
71
-
72
- return None, "Ошибка получения изображения"
73
 
74
  except Exception as e:
75
 
76
- return None, "Ошибка: " + str(e)
77
-
78
-
79
- # =========================
80
- # ПРОСТОЕ УЛУЧШЕНИЕ
81
- # =========================
82
-
83
- def improve(idea):
84
-
85
- if not idea:
86
- return ""
87
-
88
- return (
89
- idea
90
- + ", cinematic composition, "
91
- + "photorealistic, highly detailed, "
92
- + "realistic lighting, realistic shadows, "
93
- + "natural colors, detailed environment, "
94
- + "professional photography, sharp focus, "
95
- + "depth of field, 8K"
96
- )
97
-
98
 
99
- # =========================
100
- # АВТО
101
- # =========================
102
 
103
- async def auto(idea):
104
 
105
  if not idea:
106
  return "", None, "Введите идею!"
107
 
108
- prompt = improve(idea)
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
- image, status = await generate(prompt)
111
 
112
- return prompt, image, status
113
 
114
 
115
- # =========================
116
- # ИНТЕРФЕЙС
117
- # =========================
118
 
119
- with gr.Blocks() as app:
120
 
121
- gr.Markdown("# 🤖 MODARA AL")
122
  gr.Markdown("Ваш личный AI-агент")
123
 
124
- idea = gr.Textbox(
125
- label="Что создать?",
126
- placeholder="BMW M5 CS едет по ночному Дубаю"
127
- )
128
 
129
- auto_button = gr.Button(
130
- "⚡ АВТО",
131
- variant="primary"
132
- )
133
 
134
- image_button = gr.Button(
135
- "🎨 Только картинка"
136
- )
 
 
 
 
 
 
 
137
 
138
- status = gr.Textbox(
139
- label="Статус"
 
140
  )
141
 
142
- prompt = gr.Textbox(
143
- label="Улучшенный промпт"
 
144
  )
145
 
146
- image = gr.Image(
147
  label="Результат"
148
  )
149
 
150
 
151
- auto_button.click(
152
- auto,
153
- inputs=idea,
154
- outputs=[prompt, image, status]
 
 
 
155
  )
156
 
157
 
158
- image_button.click(
159
- generate,
160
- inputs=idea,
161
- outputs=[image, status]
 
 
 
 
162
  )
163
 
164
 
165
- app.launch()
166
 
167
  </script>
168
 
 
1
  <!DOCTYPE html>
2
+ <html lang="en" translate="no">
3
  <head>
4
  <meta charset="utf-8">
5
  <meta name="google" content="notranslate">
6
 
7
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.js"></script>
 
 
8
 
9
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@gradio/lite/dist/lite.css" />
 
10
  </head>
11
 
12
+ <body style="background-color: #0f172a; color: white; padding: 15px;">
13
 
14
  <gradio-app>
15
 
 
20
  from js import fetch
21
 
22
 
23
+ async def generate_img(prompt):
 
 
 
 
24
 
25
  if not prompt:
26
+ return None, "Введите описание идеи!"
27
 
28
  try:
29
 
30
+ response = await fetch(
31
  "https://mrfakename-z-image-turbo.hf.space/call/predict",
32
  method="POST",
33
+ headers={
34
+ "Content-Type": "application/json"
35
+ },
36
+ body=json.dumps({
37
+ "data": [prompt]
38
+ })
39
  )
40
 
41
+ res_data = await response.json()
 
42
 
43
+ event_id = res_data.get("event_id")
 
44
 
45
+ res_event = await fetch(
46
+ f"https://mrfakename-z-image-turbo.hf.space/call/predict/{event_id}"
 
47
  )
48
 
49
+ text_data = await res_event.text()
50
 
51
+ for line in text_data.split("\n"):
52
 
53
  if line.startswith("data:"):
54
 
55
+ img_json = json.loads(line[5:])
 
 
 
 
56
 
57
+ return (
58
+ img_json[0][0]["url"],
59
+ "Успешно сгенерировано!"
60
+ )
61
 
62
+ return None, "Ошибка получения данных."
 
 
 
63
 
64
  except Exception as e:
65
 
66
+ return None, f"Ошибка: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
 
 
 
68
 
69
+ async def auto_run(idea):
70
 
71
  if not idea:
72
  return "", None, "Введите идею!"
73
 
74
+ prompt = (
75
+ f"{idea}, "
76
+ "cinematic composition, "
77
+ "photorealistic, "
78
+ "highly detailed, "
79
+ "realistic lighting, "
80
+ "realistic shadows, "
81
+ "natural colors, "
82
+ "detailed environment, "
83
+ "professional photography, "
84
+ "sharp focus, "
85
+ "depth of field, "
86
+ "8K quality"
87
+ )
88
 
89
+ img, status = await generate_img(prompt)
90
 
91
+ return prompt, img, f"[АВТО] {status}"
92
 
93
 
94
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
 
 
95
 
96
+ gr.Markdown("# 🤖 MODARA_Al")
97
 
 
98
  gr.Markdown("Ваш личный AI-агент")
99
 
100
+ with gr.Row():
 
 
 
101
 
102
+ user_idea = gr.Textbox(
103
+ label="Что создать?",
104
+ placeholder="BMW M5 CS едет по ночному Дубаю"
105
+ )
106
 
107
+ with gr.Row():
108
+
109
+ btn_auto = gr.Button(
110
+ "⚡ АВТО",
111
+ variant="primary"
112
+ )
113
+
114
+ btn_img = gr.Button(
115
+ "🎨 Только картинка"
116
+ )
117
 
118
+ status_box = gr.Textbox(
119
+ label="Статус",
120
+ interactive=False
121
  )
122
 
123
+ final_prompt = gr.Textbox(
124
+ label="Улучшенный промпт",
125
+ interactive=False
126
  )
127
 
128
+ output_image = gr.Image(
129
  label="Результат"
130
  )
131
 
132
 
133
+ btn_img.click(
134
+ fn=generate_img,
135
+ inputs=[user_idea],
136
+ outputs=[
137
+ output_image,
138
+ status_box
139
+ ]
140
  )
141
 
142
 
143
+ btn_auto.click(
144
+ fn=auto_run,
145
+ inputs=[user_idea],
146
+ outputs=[
147
+ final_prompt,
148
+ output_image,
149
+ status_box
150
+ ]
151
  )
152
 
153
 
154
+ demo.launch()
155
 
156
  </script>
157