arunprasadh commited on
Commit
d97b1f9
·
verified ·
1 Parent(s): 798cf11

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -18
app.py CHANGED
@@ -52,32 +52,22 @@ custom_role_conversions=None,
52
  # @tool
53
  # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
54
  @tool
55
- def generate_image_from_text(prompt: str)-> None:
56
- """Generates and displays an image based on the given text prompt.
57
-
58
- Args:
59
- prompt: A string describing the image to be generated.
60
-
61
- Returns:
62
- Displays the generated image.
63
- """
64
  try:
65
- # Load the image generation tool
66
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
67
-
68
- # Generate the image and get the URL (if applicable)
69
  image_url = image_generation_tool(prompt)
70
-
71
  # Fetch the image from the URL
72
  response = requests.get(image_url)
73
  image = Image.open(io.BytesIO(response.content))
74
-
75
- # Display the image
76
- image.show()
77
-
78
  except Exception as e:
79
  print(f"Error generating image: {str(e)}")
80
-
81
  with open("prompts.yaml", 'r') as stream:
82
  prompt_templates = yaml.safe_load(stream)
83
 
 
52
  # @tool
53
  # image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
54
  @tool
55
+ def generate_image_from_text(prompt: str) -> None:
56
+ """Generates and displays an image based on the given text prompt."""
 
 
 
 
 
 
 
57
  try:
 
58
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
 
 
59
  image_url = image_generation_tool(prompt)
60
+
61
  # Fetch the image from the URL
62
  response = requests.get(image_url)
63
  image = Image.open(io.BytesIO(response.content))
64
+
65
+ # Display the image inline in Jupyter Notebook
66
+ display.display(image)
67
+
68
  except Exception as e:
69
  print(f"Error generating image: {str(e)}")
70
+
71
  with open("prompts.yaml", 'r') as stream:
72
  prompt_templates = yaml.safe_load(stream)
73