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

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +88 -85
index.html CHANGED
@@ -1,15 +1,15 @@
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,139 +20,142 @@ import json
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
 
158
  </gradio-app>
 
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
  </head>
11
 
12
+ <body>
13
 
14
  <gradio-app>
15
 
 
20
  from js import fetch
21
 
22
 
23
+ async def generate_image(prompt):
24
 
25
+ if not prompt or not prompt.strip():
26
+ return None, "❌ Напиши, что нужно создать"
27
 
28
  try:
 
29
  response = await fetch(
30
  "https://mrfakename-z-image-turbo.hf.space/call/predict",
31
+ {
32
+ "method": "POST",
33
+ "headers": {
34
+ "Content-Type": "application/json"
35
+ },
36
+ "body": json.dumps({
37
+ "data": [prompt]
38
+ })
39
+ }
40
  )
41
 
42
+ data = await response.json()
43
+ event_id = data.get("event_id")
44
 
45
+ if not event_id:
46
+ return None, "❌ Сервер не вернул event_id"
47
 
48
+ result = await fetch(
49
  f"https://mrfakename-z-image-turbo.hf.space/call/predict/{event_id}"
50
  )
51
 
52
+ text = await result.text()
53
 
54
+ for line in text.splitlines():
55
 
56
  if line.startswith("data:"):
57
 
58
+ raw = line[5:].strip()
59
 
60
+ if not raw:
61
+ continue
 
 
62
 
63
+ result_data = json.loads(raw)
64
 
65
+ try:
66
+ image_url = result_data[0][0]["url"]
67
+ return image_url, "✅ Изображение готово!"
68
+ except:
69
+ pass
70
+
71
+ return None, "❌ Не удалось получить изображение"
72
 
73
+ except Exception as e:
74
+ return None, "❌ Ошибка: " + str(e)
75
 
76
 
77
+ def improve_prompt(idea):
78
 
79
+ if not idea or not idea.strip():
80
+ return ""
81
 
82
+ return (
83
+ idea.strip()
84
+ + ", cinematic composition, "
85
+ + "highly detailed, photorealistic, "
86
+ + "realistic lighting, realistic shadows, "
87
+ + "detailed environment, sharp focus, "
88
+ + "depth of field, professional photography, "
89
+ + "high quality"
 
 
 
 
 
90
  )
91
 
 
92
 
93
+ async def auto_generate(idea):
94
 
95
+ if not idea or not idea.strip():
96
+ return "", None, "❌ Напиши идею"
97
 
98
+ prompt = improve_prompt(idea)
99
 
100
+ image, status = await generate_image(prompt)
101
 
102
+ return prompt, image, status
103
 
 
104
 
105
+ with gr.Blocks() as app:
106
+
107
+ gr.Markdown(
108
+ """
109
+ # 🤖 MODARA_Al
110
+ ### Твой личный AI-агент
111
+ """
112
+ )
113
+
114
+ idea = gr.Textbox(
115
+ label="💡 Что создать?",
116
+ placeholder="Например: BMW M5 CS едет ночью по Дубаю",
117
+ lines=3
118
+ )
119
 
120
  with gr.Row():
121
 
122
+ auto_button = gr.Button(
123
  "⚡ АВТО",
124
  variant="primary"
125
  )
126
 
127
+ image_button = gr.Button(
128
+ "🎨 СОЗДАТЬ"
129
  )
130
 
131
+ status = gr.Textbox(
132
+ label="📊 Статус",
133
  interactive=False
134
  )
135
 
136
+ improved = gr.Textbox(
137
+ label="✨ Улучшенный промпт",
138
+ interactive=False,
139
+ lines=5
140
  )
141
 
142
+ result = gr.Image(
143
+ label="🖼️ Результат"
144
  )
145
 
146
 
147
+ auto_button.click(
148
+ auto_generate,
149
+ inputs=idea,
150
+ outputs=[improved, result, status]
 
 
 
151
  )
152
 
153
+ image_button.click(
154
+ generate_image,
155
+ inputs=idea,
156
+ outputs=[result, status]
 
 
 
 
 
157
  )
158
 
 
 
 
159
  </script>
160
 
161
  </gradio-app>