File size: 7,107 Bytes
8322301
 
 
d1cc8ad
8322301
 
 
 
 
d1cc8ad
 
 
 
 
 
 
 
8322301
d1cc8ad
8322301
 
 
 
 
 
 
 
d1cc8ad
8322301
 
d1cc8ad
 
 
 
 
8322301
 
 
 
 
 
 
 
 
9c5e626
8322301
 
 
 
 
 
 
 
 
 
 
9c5e626
8322301
 
d1cc8ad
 
 
9c5e626
 
 
 
2c1d8b2
9c5e626
 
 
8322301
 
 
 
9c5e626
 
 
 
 
2c1d8b2
9c5e626
8322301
 
 
 
 
d1cc8ad
 
 
9c5e626
 
 
 
 
 
 
 
 
 
 
 
 
d1cc8ad
8322301
 
9c5e626
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8322301
9c5e626
8322301
 
 
 
 
 
 
 
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# gradio_interface.py
import gradio as gr
import modal
from config.models import models_modal  # Indirect import
#from img_gen import generate_image

print("Hello from gradio_interface_head!")

# Modal remote function synchronously
def generate(adventurer_id,
            #prompt_dropdown,
            #character_dropdown,
            scene_dropdown,
            #model_dropdown, 
            custom_prompt_input,
            cpu_gpu ="GPU",
        ):
    # Debug: 
    debug_message = f"Debug: Button clicked! Inputs - ID: {adventurer_id}, Scene: {scene_dropdown}, Custom Prompt: {custom_prompt_input}"
    print(debug_message)  # Print to console for debugging
    try:
        # Check for CPU/GPU dropdown option
        if cpu_gpu == "GPU":
            f = modal.Function.from_name("LS-img-gen-modal", "generate_image_gpu")
        else:
            f = modal.Function.from_name("LS-img-gen-modal", "generate_image_cpu")

        print ("Sending to external function")
       # Import the remote function
        image_path, message = f.remote(
                            adventurer_id,
                            #prompt_dropdown, 
                            #character_dropdown,
                            scene_dropdown,
                            #model_dropdown,
                            custom_prompt_input,
                            )
        return image_path, message
    except Exception as e:
        return None, f"Error calling generate_image function: {e}"
    

# Gradio Interface
def gradio_interface():

    with gr.Blocks(css="""
                    .gradio-container {
                        background-image: url(''); 
                        background-size: cover;
                        background-position: center;
                    }
                    .output-image img {
                     width: 2500px; /* Force image to fill container width */
                     object-fit: cover; /* ACTIVATE FOR IMAGE-FIT CONTAINER */
                    }
                    """) as demo:
        gr.Markdown("# ========== Loot Survivor - AI Image Generator ========== modal GPU")
        with gr.Row():
            # Set default values for dropdowns
            #prompt_dropdown = gr.Dropdown(choices=[p["alias"] for p in prompts], label="Select Beast", value=prompts[0]["alias"])
            adventurer_id = gr.Number(label="Adventurer ID:")
            #character_dropdown = gr.Dropdown(choices=["Wizard", "Hunter", "Warrior"], label="Select Character Type", value="Wizard")
            scene_dropdown1 = gr.Dropdown(choices=["Adventurer Portait", "Encounter", "Beast Portait", "Last Battle", "Loot Bag"], label="Select Scene", value="Adventurer Portait", visible=False )          
            scene_dropdown2 = gr.Dropdown(choices=["Adventurer Portait", "Encounter", "Beast Portait", "Last Battle", "Loot Bag"], label="Select Scene", value="Beast Portait", visible=False )          
            scene_dropdown3 = gr.Dropdown(choices=["Adventurer Portait", "Encounter", "Beast Portait", "Last Battle", "Loot Bag"], label="Select Scene", value="Encounter", visible=False )          
            scene_dropdown4 = gr.Dropdown(choices=["Adventurer Portait", "Encounter", "Beast Portait", "Last Battle", "Loot Bag"], label="Select Scene", value="Last Battle", visible=False )          
            scene_dropdown5 = gr.Dropdown(choices=["Adventurer Portait", "Encounter", "Beast Portait", "Last Battle", "Final Scene"], label="Select Scene", value="Final Scene", visible=False )          
            custom_prompt_input = gr.Textbox(label="Custom Prompt (Optional)", placeholder="Enter additional details (max 200 chars)...", max_lines=1, max_length=200)
            #model_dropdown = gr.Dropdown(choices=[m["alias"] for m in models], label="Select Model", value=models[0]["alias"])
        #with gr.Row():
            # Add a text box for custom user input (max 200 characters)
        with gr.Row():
            generate_button = gr.Button("Generate Image")
        with gr.Row():
            output_image1 = gr.Image(elem_classes="output-image", label="Adventurer Portait", show_label=True, scale=1, width="100%")
            output_image2 = gr.Image(elem_classes="output-image", label="Beast Portait", show_label=True, scale=1, width="100%")
        with gr.Row():
            output_image3 = gr.Image(elem_classes="output-image", label="Encounter", show_label=True, scale=1, width="100%")
            output_image4 = gr.Image(elem_classes="output-image", label="Last Battle", show_label=True, scale=1, width="100%")
            output_image5 = gr.Image(elem_classes="output-image", label="Final Scene", show_label=True, scale=1, width="100%")
        
        with gr.Row():
            status_text = gr.Textbox(label="Status", placeholder="Waiting for input...", interactive=False)
        # Connect the button to the function
        generate_button.click(
            generate,
            inputs=[adventurer_id,
                    #prompt_dropdown, 
                    #character_dropdown,
                    scene_dropdown1,
                    #model_dropdown,
                    custom_prompt_input,
                    ],
            outputs=[output_image1, status_text],
            show_progress_on=output_image1,
        )
        generate_button.click(
            generate,
            inputs=[adventurer_id,
                    #prompt_dropdown, 
                    #character_dropdown,
                    scene_dropdown2,
                    #model_dropdown,
                    custom_prompt_input,
                    ],
            outputs=[output_image2, status_text],
            show_progress_on=output_image2,

        )
        generate_button.click(
            generate,
            inputs=[adventurer_id,
                    #prompt_dropdown, 
                    #character_dropdown,
                    scene_dropdown3,
                    #model_dropdown,
                    custom_prompt_input,
                    ],
            outputs=[output_image3, status_text],
            show_progress_on=output_image3,

        )
        generate_button.click(
            generate,
            inputs=[adventurer_id,
                    #prompt_dropdown, 
                    #character_dropdown,
                    scene_dropdown4,
                    #model_dropdown,
                    custom_prompt_input,
                    ],
            outputs=[output_image4, status_text],
            show_progress_on=output_image4,

        )        
        generate_button.click(
            generate,
            inputs=[adventurer_id,
                    #prompt_dropdown, 
                    #character_dropdown,
                    scene_dropdown5,
                    #model_dropdown,
                    custom_prompt_input,
                    ],
            outputs=[output_image5, status_text],
            show_progress_on=output_image5,

        )
        
    return demo

# Create the demo instance
demo = gradio_interface()

# Only launch if running directly
if __name__ == "__main__":
        demo.queue().launch()