Julien6411 commited on
Commit
44fc028
·
verified ·
1 Parent(s): f43cc5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -11,7 +11,6 @@ from PIL import Image
11
  hf_token = os.getenv("HF_ACCESS_TOKEN")
12
 
13
 
14
-
15
  @tool
16
  def generate_landscape_image(timezone: str) -> Image.Image:
17
  """
@@ -46,14 +45,17 @@ def generate_landscape_image(timezone: str) -> Image.Image:
46
  else:
47
  prompt = "A serene nighttime landscape featuring a luminous moon shining in the dark sky."
48
 
49
- # Generate the image using the image generation tool from Space
50
  result = image_generation_tool(prompt)
51
- # result is a file path; open the image using PIL
52
- image = Image.open(result)
 
 
 
 
 
53
  return image
54
  except Exception as e:
55
- # If there's an error, you can either return a string or raise an error.
56
- # Here we return a string, but Gradio might display it as plain text.
57
  return f"Error generating image for timezone '{timezone}': {str(e)}"
58
 
59
  @tool
 
11
  hf_token = os.getenv("HF_ACCESS_TOKEN")
12
 
13
 
 
14
  @tool
15
  def generate_landscape_image(timezone: str) -> Image.Image:
16
  """
 
45
  else:
46
  prompt = "A serene nighttime landscape featuring a luminous moon shining in the dark sky."
47
 
48
+ # Call the image generation tool loaded from Space
49
  result = image_generation_tool(prompt)
50
+
51
+ # If the result is an AgentImage, extract the underlying image.
52
+ if hasattr(result, "to_raw"):
53
+ image = result.to_raw()
54
+ else:
55
+ # Otherwise assume it's a file path and open it.
56
+ image = Image.open(result)
57
  return image
58
  except Exception as e:
 
 
59
  return f"Error generating image for timezone '{timezone}': {str(e)}"
60
 
61
  @tool