Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,66 +6,9 @@ import tempfile
|
|
6 |
import os
|
7 |
import uuid
|
8 |
import gradio as gr
|
|
|
9 |
|
10 |
|
11 |
-
# function to plot and save an AgentImage
|
12 |
-
def plot_and_save_agent_image(agent_image, save_path=None):
|
13 |
-
# Convert AgentImage to a raw PIL Image
|
14 |
-
pil_image = agent_image.to_raw()
|
15 |
-
|
16 |
-
# Plot the image using PIL's show method
|
17 |
-
pil_image.show()
|
18 |
-
|
19 |
-
# If save_path is provided, save the image
|
20 |
-
if save_path:
|
21 |
-
pil_image.save(save_path)
|
22 |
-
print(f"Image saved to {save_path}")
|
23 |
-
else:
|
24 |
-
print("No save path provided. Image not saved.")
|
25 |
-
|
26 |
-
|
27 |
-
def generate_prompts_for_object(object_name):
|
28 |
-
prompts = {
|
29 |
-
"past": f"Show an old version of a {object_name} from its early days.",
|
30 |
-
"present": f"Show a {object_name} with from present with current features/design/technology.",
|
31 |
-
"future": f"Show a futuristic version of a {object_name}, by predicting advanced features and futuristic design."
|
32 |
-
}
|
33 |
-
return prompts
|
34 |
-
|
35 |
-
|
36 |
-
# Function to generate the car industry history
|
37 |
-
def generate_object_history(object_name):
|
38 |
-
images = []
|
39 |
-
|
40 |
-
# Get prompts for the object
|
41 |
-
prompts = generate_prompts_for_object(object_name)
|
42 |
-
|
43 |
-
# Generate sequential images and display them
|
44 |
-
for time_period, frame in prompts.items():
|
45 |
-
print(f"Generating {time_period} frame: {frame}")
|
46 |
-
result = agent.run(frame) # The tool generates the image
|
47 |
-
|
48 |
-
# Append the image to the list for GIF creation
|
49 |
-
images.append(result.to_raw()) # Ensure we're using raw image for GIF
|
50 |
-
|
51 |
-
# Save each image with the appropriate name (past, present, future)
|
52 |
-
image_filename = f"{object_name}_{time_period}.png"
|
53 |
-
plot_and_save_agent_image(result, save_path=image_filename)
|
54 |
-
|
55 |
-
|
56 |
-
# Create GIF from images
|
57 |
-
gif_path = f"{object_name}_evolution.gif"
|
58 |
-
images[0].save(
|
59 |
-
gif_path,
|
60 |
-
save_all=True,
|
61 |
-
append_images=images[1:],
|
62 |
-
duration=1000, # Duration in milliseconds for each frame
|
63 |
-
loop=0 # Infinite loop
|
64 |
-
)
|
65 |
-
|
66 |
-
# Return images and GIF path
|
67 |
-
return images, gif_path
|
68 |
-
|
69 |
# Import text-to-image tool from Hub
|
70 |
# m-ric/text-to-image model generates images based on textual descriptions.
|
71 |
image_generation_tool = load_tool("m-ric/text-to-image", cache=False) #cache=False ensures it fetches the latest tool updates directly from the Hub.
|
|
|
6 |
import os
|
7 |
import uuid
|
8 |
import gradio as gr
|
9 |
+
import Methods
|
10 |
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
# Import text-to-image tool from Hub
|
13 |
# m-ric/text-to-image model generates images based on textual descriptions.
|
14 |
image_generation_tool = load_tool("m-ric/text-to-image", cache=False) #cache=False ensures it fetches the latest tool updates directly from the Hub.
|