|
from transformers import load_tool, ReactCodeAgent, HfApiEngine |
|
from PIL import Image |
|
import torch |
|
import numpy as np |
|
import tempfile |
|
import os |
|
import uuid |
|
import gradio as gr |
|
from Methods import * |
|
|
|
|
|
|
|
|
|
image_generation_tool = load_tool("m-ric/text-to-image", cache=False) |
|
|
|
|
|
|
|
from transformers.agents.search import DuckDuckGoSearchTool |
|
|
|
search_tool = DuckDuckGoSearchTool() |
|
|
|
|
|
llm_engine = HfApiEngine("Qwen/Qwen2.5-72B-Instruct") |
|
|
|
agent = ReactCodeAgent(tools=[image_generation_tool, search_tool], llm_engine=llm_engine) |
|
|
|
|
|
|
|
|
|
def create_gradio_interface(): |
|
with gr.Blocks() as demo: |
|
gr.Markdown("# Object Evolution Generator") |
|
|
|
|
|
gr.Markdown(""" |
|
## Welcome to the Object Evolution Generator! |
|
This app allows you to generate visualizations of how an object, like a bicycle or a car, may have evolved over time. |
|
It generates images of the object in the past, present, and future based on your input. |
|
|
|
### Default Example: Evolution of a Car |
|
Below, you can see a precomputed example of a "car" evolution. Enter another object to generate its evolution. |
|
""") |
|
|
|
|
|
default_images = [ |
|
("car_past.png", "Car - Past"), |
|
("car_present.png", "Car - Present"), |
|
("car_future.png", "Car - Future") |
|
] |
|
default_gif_path = "car_evolution.gif" |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
|
|
object_name_input = gr.Textbox(label="Enter an object name (e.g., bicycle, phone)", |
|
placeholder="Enter an object name", |
|
lines=1) |
|
|
|
|
|
generate_button = gr.Button("Generate Evolution") |
|
|
|
|
|
image_gallery = gr.Gallery(label="Generated Images", show_label=True, columns=3, rows=1, |
|
value=default_images) |
|
|
|
|
|
gif_output = gr.Image(label="Generated GIF", show_label=True, value=default_gif_path) |
|
|
|
|
|
generate_button.click(fn=generate_object_history, inputs=[object_name_input], outputs=[image_gallery, gif_output]) |
|
|
|
return demo |
|
|
|
|
|
demo = create_gradio_interface() |
|
|
|
|
|
demo.launch(share=True) |
|
|