RanM commited on
Commit
e15ee10
·
verified ·
1 Parent(s): 03835a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -11
app.py CHANGED
@@ -10,28 +10,23 @@ model = AutoPipelineForText2Image.from_pretrained("stabilityai/sdxl-turbo")
10
 
11
  async def generate_image(prompt):
12
  try:
13
- # Use a higher value for num_inference_steps to avoid IndexError
14
- num_inference_steps = 3 # Adjust this value as needed
15
-
16
- # Use the model to generate an image
17
  output = await asyncio.to_thread(
18
  model,
19
  prompt=prompt,
20
- num_inference_steps=num_inference_steps, # Use a higher value for inference steps
21
- guidance_scale=0.0, # Typical value for guidance scale in image generation
22
- output_type="pil" # Directly get PIL Image objects
23
  )
24
-
25
- # Check for output validity and return
26
  if output.images:
27
  return output.images[0]
28
  else:
29
  raise Exception("No images returned by the model.")
30
-
31
  except Exception as e:
32
  print(f"Error generating image: {e}")
33
  traceback.print_exc()
34
- return None # Return None on error to handle it gracefully in the UI
 
35
 
36
  async def inference(sentence_mapping, character_dict, selected_style):
37
  images = []
 
10
 
11
  async def generate_image(prompt):
12
  try:
13
+ num_inference_steps = 4 # Increased inference steps
 
 
 
14
  output = await asyncio.to_thread(
15
  model,
16
  prompt=prompt,
17
+ num_inference_steps=num_inference_steps,
18
+ guidance_scale=0.0,
19
+ output_type="pil"
20
  )
 
 
21
  if output.images:
22
  return output.images[0]
23
  else:
24
  raise Exception("No images returned by the model.")
 
25
  except Exception as e:
26
  print(f"Error generating image: {e}")
27
  traceback.print_exc()
28
+ return None
29
+
30
 
31
  async def inference(sentence_mapping, character_dict, selected_style):
32
  images = []