Rooni commited on
Commit
a2c470a
1 Parent(s): 687d54f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -5
app.py CHANGED
@@ -1,6 +1,11 @@
1
  import gradio as gr
2
  import requests
3
  import random
 
 
 
 
 
4
 
5
  def generate_image(prompt, style, width, height, seed):
6
  if seed == -1:
@@ -56,14 +61,22 @@ def generate_image(prompt, style, width, height, seed):
56
  "Экспериментальный": "experimental style, abstract, unconventional, detailed patterns, vibrant colors"
57
  }
58
 
59
- prompt = style_tags.get(style, "") + " " + prompt if style_tags.get(style, "") else prompt
60
  prompt = prompt.strip()
61
 
62
  url = f"https://image.pollinations.ai/prompt/{prompt}?width={width}&height={height}&seed={seed}&nologo=true&nofeed=true"
63
- response = requests.get(url, timeout=150)
64
- if response.status_code == 200:
65
- return response.content
66
- else:
 
 
 
 
 
 
 
 
67
  return None
68
 
69
  # Создаем интерфейс Gradio
 
1
  import gradio as gr
2
  import requests
3
  import random
4
+ import logging
5
+
6
+ # Настройка логирования
7
+ logging.basicConfig(level=logging.INFO)
8
+ logger = logging.getLogger(__name__)
9
 
10
  def generate_image(prompt, style, width, height, seed):
11
  if seed == -1:
 
61
  "Экспериментальный": "experimental style, abstract, unconventional, detailed patterns, vibrant colors"
62
  }
63
 
64
+ prompt = style_tags.get(style, "") + ". " + prompt if style_tags.get(style, "") else prompt
65
  prompt = prompt.strip()
66
 
67
  url = f"https://image.pollinations.ai/prompt/{prompt}?width={width}&height={height}&seed={seed}&nologo=true&nofeed=true"
68
+ logger.info(f"Generated URL: {url}")
69
+
70
+ try:
71
+ response = requests.get(url, timeout=150)
72
+ if response.status_code == 200:
73
+ logger.info("Image generated successfully")
74
+ return response.content
75
+ else:
76
+ logger.error(f"Failed to generate image. Status code: {response.status_code}, Response: {response.text}")
77
+ return None
78
+ except requests.exceptions.RequestException as e:
79
+ logger.error(f"Request exception: {e}")
80
  return None
81
 
82
  # Создаем интерфейс Gradio