File size: 3,159 Bytes
5167fb6
 
 
 
 
 
 
 
92061e6
5167fb6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7c1e90
5167fb6
 
 
 
 
 
 
 
 
 
f7c1e90
 
 
5167fb6
 
5420ab6
 
 
 
 
 
 
 
5167fb6
 
 
f7c1e90
5167fb6
 
 
 
 
 
 
f7c1e90
 
5167fb6
 
f7c1e90
5167fb6
 
 
 
 
 
cce70f0
5167fb6
 
 
f7c1e90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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 *


# Import text-to-image tool from Hub 
# m-ric/text-to-image model generates images based on textual descriptions.
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.

# Import search tool from LangChain
#This tool allows the agent to search for and retrieve information from the web.
from transformers.agents.search import DuckDuckGoSearchTool

search_tool = DuckDuckGoSearchTool()

# Qwen2.5-72B-Instruct is a specific, a LLM fine-tuned for instruction-following tasks.
llm_engine = HfApiEngine("Qwen/Qwen2.5-72B-Instruct") 
# Initialize the agent with both tools
agent = ReactCodeAgent(tools=[image_generation_tool, search_tool], llm_engine=llm_engine)



# Gradio interface
def create_gradio_interface():
    with gr.Blocks() as demo:
        gr.Markdown("# Object Evolution Generator")
        
        # Add a section for instructions
        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.
        """)

        # Paths to the precomputed files
        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():
                # Textbox for user to input an object name
                object_name_input = gr.Textbox(label="Enter an object name (e.g., bicycle, phone)", 
                                              placeholder="Enter an object name", 
                                              lines=1)

                # Button to trigger the generation of images and GIF
                generate_button = gr.Button("Generate Evolution")
    
                # Gradio Gallery component to display the images
                image_gallery = gr.Gallery(label="Generated Images", show_label=True, columns=3, rows=1, 
                                           value=default_images)

                # Output for the generated GIF
                gif_output = gr.Image(label="Generated GIF", show_label=True, value=default_gif_path)
         
        # Set the action when the button is clicked
        generate_button.click(fn=generate_object_history, inputs=[object_name_input], outputs=[image_gallery, gif_output])
    
    return demo

# Launch the Gradio app 
demo = create_gradio_interface()

# To make it permanent and hosted, we can use Gradio's 'share' argument or host it on a server.
demo.launch(share=True)