Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,10 +14,55 @@ models_list = ["AbsoluteReality 1.8.1", "DALL-E 3 XL", "Playground 2", "Openjour
|
|
| 14 |
|
| 15 |
# PLEASE ❤ like ❤ this space. Please like me. I am 12 years old, one of my projects is: https://ai-hub.rf.gd . I live in Russia, I don't know English very well. Therefore, I apologize that there is only Russian here, but I think it will not be difficult to translate all this. (For example, using gpt)
|
| 16 |
|
| 17 |
-
def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7):
|
| 18 |
if prompt == "" or prompt == None:
|
| 19 |
return None
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN"), os.getenv("HF_READ_TOKEN_2"), os.getenv("HF_READ_TOKEN_3"), os.getenv("HF_READ_TOKEN_4"), os.getenv("HF_READ_TOKEN_5")]) # it is free
|
| 23 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
@@ -124,6 +169,8 @@ with gr.Blocks(css=css) as dalle:
|
|
| 124 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
| 125 |
with gr.Row():
|
| 126 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
|
|
|
|
|
|
| 127 |
|
| 128 |
with gr.Tab("Информация"):
|
| 129 |
with gr.Row():
|
|
@@ -134,6 +181,6 @@ with gr.Blocks(css=css) as dalle:
|
|
| 134 |
with gr.Row():
|
| 135 |
image_output = gr.Image(type="pil", label="Изображение", elem_id="gallery")
|
| 136 |
|
| 137 |
-
text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength], outputs=image_output)
|
| 138 |
|
| 139 |
dalle.launch(show_api=False, share=False)
|
|
|
|
| 14 |
|
| 15 |
# PLEASE ❤ like ❤ this space. Please like me. I am 12 years old, one of my projects is: https://ai-hub.rf.gd . I live in Russia, I don't know English very well. Therefore, I apologize that there is only Russian here, but I think it will not be difficult to translate all this. (For example, using gpt)
|
| 16 |
|
| 17 |
+
def query(prompt, model, is_negative=False, steps=30, cfg_scale=7, sampler="DPM++ 2M Karras", seed=-1, strength=0.7, gpt):
|
| 18 |
if prompt == "" or prompt == None:
|
| 19 |
return None
|
| 20 |
|
| 21 |
+
if gpt:
|
| 22 |
+
payload = {
|
| 23 |
+
"model": "gpt-4-vision-preview",
|
| 24 |
+
"messages": [
|
| 25 |
+
{
|
| 26 |
+
"role": "user",
|
| 27 |
+
"content": start,
|
| 28 |
+
},
|
| 29 |
+
{
|
| 30 |
+
"role": "user",
|
| 31 |
+
"content": instruction,
|
| 32 |
+
}
|
| 33 |
+
],
|
| 34 |
+
"max_tokens": 4095,
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
# API ключ для OpenAI
|
| 39 |
+
api_key = os.getenv("API_KEY_OPENAI")
|
| 40 |
+
|
| 41 |
+
# Заголовки для запроса
|
| 42 |
+
headers = {
|
| 43 |
+
'Authorization': f'Bearer {api_key}',
|
| 44 |
+
'Content-Type': 'application/json',
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
# URL для запроса к API OpenAI
|
| 48 |
+
url = "https://api.openai.com/v1/chat/completions"
|
| 49 |
+
|
| 50 |
+
# Отправляем запрос в OpenAI
|
| 51 |
+
response = requests.post(url, headers=headers, json=payload)
|
| 52 |
+
|
| 53 |
+
# Проверяем ответ и возвращаем результат
|
| 54 |
+
if response.status_code == 200:
|
| 55 |
+
response_json = response.json()
|
| 56 |
+
try:
|
| 57 |
+
# Пытаемся извлечь текст из ответа
|
| 58 |
+
return response_json["choices"][0]["message"]["content"]
|
| 59 |
+
except Exception as e:
|
| 60 |
+
# Если есть ошибка в структуре JSON, выводим ее
|
| 61 |
+
return f"Error processing the image response: {e}"
|
| 62 |
+
else:
|
| 63 |
+
# Если произошла ошибка, возвращаем сообщение об ошибке
|
| 64 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 65 |
+
|
| 66 |
|
| 67 |
API_TOKEN = random.choice([os.getenv("HF_READ_TOKEN"), os.getenv("HF_READ_TOKEN_2"), os.getenv("HF_READ_TOKEN_3"), os.getenv("HF_READ_TOKEN_4"), os.getenv("HF_READ_TOKEN_5")]) # it is free
|
| 68 |
headers = {"Authorization": f"Bearer {API_TOKEN}"}
|
|
|
|
| 169 |
strength = gr.Slider(label="Strength", value=0.7, minimum=0, maximum=1, step=0.001)
|
| 170 |
with gr.Row():
|
| 171 |
seed = gr.Slider(label="Seed", value=-1, minimum=-1, maximum=1000000000, step=1)
|
| 172 |
+
with gr.Row():
|
| 173 |
+
gpt = gr.Checkbox(label="ChatGPT")
|
| 174 |
|
| 175 |
with gr.Tab("Информация"):
|
| 176 |
with gr.Row():
|
|
|
|
| 181 |
with gr.Row():
|
| 182 |
image_output = gr.Image(type="pil", label="Изображение", elem_id="gallery")
|
| 183 |
|
| 184 |
+
text_button.click(query, inputs=[text_prompt, model, negative_prompt, steps, cfg, method, seed, strength, gpt], outputs=image_output)
|
| 185 |
|
| 186 |
dalle.launch(show_api=False, share=False)
|