-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextended_test.py
More file actions
100 lines (84 loc) · 3.96 KB
/
extended_test.py
File metadata and controls
100 lines (84 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3
"""
Расширенный тест для проверки функций генерации изображений
"""
import requests
import urllib.parse
def test_url_encoding():
"""Тестирование кодирования URL"""
print("Тестируем кодирование URL...")
# Тестируем разные промпты
test_prompts = [
"nature sunset",
"природа закат",
"a beautiful landscape with mountains",
"красивый пейзаж с горами"
]
for prompt in test_prompts:
encoded = urllib.parse.quote(prompt)
print(f"'{prompt}' -> '{encoded}'")
# Проверяем, что URL работает
url = f"https://image.pollinations.ai/prompt/{encoded}?model=flux"
try:
resp = requests.get(url, timeout=10)
if resp.ok:
print(f"✅ URL работает, размер: {len(resp.content)} байт")
else:
print(f"❌ URL не работает: {resp.status_code}")
except Exception as e:
print(f"❌ Ошибка запроса: {e}")
print()
def test_gen_img_for_bot():
"""Имитация функции gen_img_for_bot"""
def gen_img_for_bot(user_input, model):
"""Функция для генерации изображения для бота"""
try:
# Кодируем промпт для URL
encoded_prompt = urllib.parse.quote(user_input)
# Формируем URL для запроса
url = f"https://image.pollinations.ai/prompt/{encoded_prompt}?model={model}"
resp = requests.get(url)
if resp.ok:
# Для бота возвращаем URL изображения
return url
else:
return f"Ошибка генерации изображения: {resp.status_code}"
except Exception as e:
return f"Ошибка: {str(e)}"
print("Тестируем функцию gen_img_for_bot...")
# Тестируем с разными промптами
test_cases = [
("nature sunset", "flux"),
("природа закат", "flux"),
("beautiful landscape", "turbo"),
("красивый пейзаж", "kontext")
]
for prompt, model in test_cases:
print(f"\nТестируем: '{prompt}' с моделью '{model}'")
result = gen_img_for_bot(prompt, model)
print(f"Результат: {result}")
if result.startswith("https://image.pollinations.ai/"):
print("✅ Функция работает корректно!")
else:
print("❌ Функция не работает")
def test_bot_image_detection():
"""Тестирование детекции изображений в боте"""
print("\nТестируем детекцию изображений в боте...")
test_responses = [
"https://image.pollinations.ai/prompt/nature%20sunset?model=flux",
"https://example.com/image.jpg",
"https://example.com/image.png",
"https://example.com/document.pdf",
"Это просто текстовый ответ",
"Ошибка генерации изображения: 404"
]
for response in test_responses:
# Проверяем, является ли ответ URL изображения
is_image = (response.startswith(("http://", "https://")) and
("image.pollinations.ai" in response or
any(ext in response for ext in [".jpg", ".png", ".jpeg", ".gif", ".webp"])))
print(f"'{response}' -> {'✅ Изображение' if is_image else '❌ Не изображение'}")
if __name__ == "__main__":
test_url_encoding()
test_gen_img_for_bot()
test_bot_image_detection()