Update index.html
Browse files- index.html +88 -85
index.html
CHANGED
|
@@ -1,15 +1,15 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
-
<html lang="
|
| 3 |
<head>
|
| 4 |
-
<meta charset="
|
| 5 |
<meta name="google" content="notranslate">
|
| 6 |
|
| 7 |
-
<script type="module"
|
| 8 |
-
|
| 9 |
-
<
|
| 10 |
</head>
|
| 11 |
|
| 12 |
-
<body
|
| 13 |
|
| 14 |
<gradio-app>
|
| 15 |
|
|
@@ -20,139 +20,142 @@ import json
|
|
| 20 |
from js import fetch
|
| 21 |
|
| 22 |
|
| 23 |
-
async def
|
| 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 |
-
|
| 33 |
-
|
| 34 |
-
"
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
"
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
)
|
| 40 |
|
| 41 |
-
|
|
|
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
f"https://mrfakename-z-image-turbo.hf.space/call/predict/{event_id}"
|
| 47 |
)
|
| 48 |
|
| 49 |
-
|
| 50 |
|
| 51 |
-
for line in
|
| 52 |
|
| 53 |
if line.startswith("data:"):
|
| 54 |
|
| 55 |
-
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
"Успешно сгенерировано!"
|
| 60 |
-
)
|
| 61 |
|
| 62 |
-
|
| 63 |
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
|
|
|
|
| 67 |
|
| 68 |
|
| 69 |
-
|
| 70 |
|
| 71 |
-
if not idea:
|
| 72 |
-
return ""
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
"cinematic composition, "
|
| 77 |
-
"photorealistic, "
|
| 78 |
-
"
|
| 79 |
-
"
|
| 80 |
-
"
|
| 81 |
-
"
|
| 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 |
-
|
| 92 |
|
|
|
|
|
|
|
| 93 |
|
| 94 |
-
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
-
with gr.Row():
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
with gr.Row():
|
| 108 |
|
| 109 |
-
|
| 110 |
"⚡ АВТО",
|
| 111 |
variant="primary"
|
| 112 |
)
|
| 113 |
|
| 114 |
-
|
| 115 |
-
"🎨 Т
|
| 116 |
)
|
| 117 |
|
| 118 |
-
|
| 119 |
-
label="Статус",
|
| 120 |
interactive=False
|
| 121 |
)
|
| 122 |
|
| 123 |
-
|
| 124 |
-
label="Улучшенный промпт",
|
| 125 |
-
interactive=False
|
|
|
|
| 126 |
)
|
| 127 |
|
| 128 |
-
|
| 129 |
-
label="Результат"
|
| 130 |
)
|
| 131 |
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
inputs=
|
| 136 |
-
outputs=[
|
| 137 |
-
output_image,
|
| 138 |
-
status_box
|
| 139 |
-
]
|
| 140 |
)
|
| 141 |
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 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>
|