smokxy commited on
Commit
c252e89
·
1 Parent(s): 0b50b5d

update app

Browse files
Files changed (1) hide show
  1. app.py +5 -15
app.py CHANGED
@@ -24,24 +24,14 @@ def generate_image(prompt: str, style: str = "") -> str:
24
  full_prompt = f"{prompt}, {style} style" if style else prompt
25
 
26
  # Generate the image using the loaded tool
27
- # This should return a PIL image object
28
  pil_image = image_generation_tool(full_prompt)
29
 
30
- # Create a temporary file path to save the image
31
- import os
32
- import tempfile
33
-
34
- # Create temp directory if it doesn't exist
35
- temp_dir = os.path.join(tempfile.gettempdir(), "generated_images")
36
- os.makedirs(temp_dir, exist_ok=True)
37
-
38
- # Save the image to a file
39
- img_path = os.path.join(temp_dir, f"generated_{hash(full_prompt)}.png")
40
- pil_image.save(img_path)
41
-
42
- # Return the AgentImage object with the file path
43
  from smolagents.agent_types import AgentImage
44
- return AgentImage(img_path)
 
 
 
45
  except Exception as e:
46
  return f"Error generating image: {str(e)}"
47
 
 
24
  full_prompt = f"{prompt}, {style} style" if style else prompt
25
 
26
  # Generate the image using the loaded tool
 
27
  pil_image = image_generation_tool(full_prompt)
28
 
29
+ # Convert the PIL image to AgentImage
 
 
 
 
 
 
 
 
 
 
 
 
30
  from smolagents.agent_types import AgentImage
31
+ agent_image = AgentImage(pil_image)
32
+
33
+ # Return the AgentImage object
34
+ return agent_image
35
  except Exception as e:
36
  return f"Error generating image: {str(e)}"
37