Download app.py from Lokorye/new-space: direct link, hf CLI and curl.
- Browser
- Download file 2.43 kB
-
https://huggingface.co/spaces/Lokorye/new-space/resolve/main/app.py
- Command line
-
hf download hf://spaces/Lokorye/new-space/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Lokorye/new-space/resolve/main/app.py
2.43 kB
| import gradio as gr | |
| import numpy as np | |
| # Define a function to generate an image based on the input images and their influence levels | |
| def generate_image(image1, prompt1, influence1, image2, prompt2, influence2, image3, prompt3, influence3, image4, prompt4, influence4, negative_prompt): | |
| # Placeholder function to simulate image generation | |
| # In a real application, this function would use the input images, prompts, and influence levels to generate a new image | |
| rng = np.random.default_rng() | |
| combined_influence = influence1 + influence2 + influence3 + influence4 | |
| if combined_influence == 0: | |
| combined_influence = 1 # Avoid division by zero | |
| image = (influence1 * image1 + influence2 * image2 + influence3 * image3 + influence4 * image4) / combined_influence | |
| return image | |
| # Create a Gradio interface | |
| with gr.Blocks() as demo: | |
| # Define the input components for up to 4 images, prompts, and influence sliders | |
| with gr.Row(): | |
| with gr.Column(): | |
| image1 = gr.Image(label="Image 1") | |
| prompt1 = gr.Textbox(label="Prompt 1") | |
| influence1 = gr.Slider(0, 1, value=0.5, label="Influence 1") | |
| with gr.Column(): | |
| image2 = gr.Image(label="Image 2") | |
| prompt2 = gr.Textbox(label="Prompt 2") | |
| influence2 = gr.Slider(0, 1, value=0.5, label="Influence 2") | |
| with gr.Column(): | |
| image3 = gr.Image(label="Image 3") | |
| prompt3 = gr.Textbox(label="Prompt 3") | |
| influence3 = gr.Slider(0, 1, value=0.5, label="Influence 3") | |
| with gr.Column(): | |
| image4 = gr.Image(label="Image 4") | |
| prompt4 = gr.Textbox(label="Prompt 4") | |
| influence4 = gr.Slider(0, 1, value=0.5, label="Influence 4") | |
| # Define the negative prompt input | |
| negative_prompt = gr.Textbox(label="Negative Prompt") | |
| # Define the output component | |
| output_image = gr.Image(label="Generated Image") | |
| # Define the button to trigger the image generation | |
| generate_button = gr.Button("Generate Image") | |
| # Define the event listener for the button click | |
| generate_button.click( | |
| fn=generate_image, | |
| inputs=[image1, prompt1, influence1, image2, prompt2, influence2, image3, prompt3, influence3, image4, prompt4, influence4, negative_prompt], | |
| outputs=output_image | |
| ) | |
| # Launch the Gradio interface | |
| if __name__ == "__main__": | |
| demo.launch(show_error=True) |