Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1,35 +1,44 @@ | |
| 1 | 
             
            import gradio as gr
         | 
| 2 |  | 
| 3 | 
            -
             | 
| 4 | 
             
            models = {
         | 
| 5 | 
             
                "Flux Lora": "models/prashanth970/flux-lora-uncensored",
         | 
| 6 | 
             
                "TrioHMH Flux": "models/DiegoJR1973/NSFW-TrioHMH-Flux",
         | 
| 7 | 
             
                "Master": "models/pimpilikipilapi1/NSFW_master"
         | 
| 8 | 
             
            }
         | 
| 9 |  | 
|  | |
| 10 | 
             
            def generate_image(text, model_name):
         | 
| 11 | 
            -
                model_path = models[model_name]
         | 
| 12 | 
             
                print(f"Fetching model from: {model_path}")
         | 
| 13 |  | 
| 14 | 
             
                try:
         | 
| 15 | 
            -
                    model  | 
| 16 | 
            -
                     | 
| 17 | 
            -
                     | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 18 | 
             
                except Exception as e:
         | 
| 19 | 
             
                    print(f"Error loading model: {e}")
         | 
| 20 | 
             
                    return None
         | 
| 21 |  | 
| 22 | 
            -
             | 
| 23 | 
             
            interface = gr.Interface(
         | 
| 24 | 
             
                fn=generate_image,
         | 
| 25 | 
             
                inputs=[
         | 
| 26 | 
            -
                    gr.Textbox(label="Type here your imagination:", placeholder="Type your description here..."),
         | 
| 27 | 
            -
                    gr.Dropdown(label="Select Model", choices=list(models.keys()), value="Flux Lora")
         | 
| 28 | 
             
                ],
         | 
| 29 | 
            -
                outputs=gr.Image(label="Generated Image"),
         | 
| 30 | 
            -
                theme="NoCrypt/miku",
         | 
| 31 | 
             
                description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
         | 
| 32 | 
             
            )
         | 
| 33 |  | 
| 34 | 
            -
             | 
| 35 | 
             
            interface.launch()
         | 
|  | |
| 1 | 
             
            import gradio as gr
         | 
| 2 |  | 
| 3 | 
            +
            # Define the available models
         | 
| 4 | 
             
            models = {
         | 
| 5 | 
             
                "Flux Lora": "models/prashanth970/flux-lora-uncensored",
         | 
| 6 | 
             
                "TrioHMH Flux": "models/DiegoJR1973/NSFW-TrioHMH-Flux",
         | 
| 7 | 
             
                "Master": "models/pimpilikipilapi1/NSFW_master"
         | 
| 8 | 
             
            }
         | 
| 9 |  | 
| 10 | 
            +
            # Function to generate an image from text using the selected model
         | 
| 11 | 
             
            def generate_image(text, model_name):
         | 
| 12 | 
            +
                model_path = models[model_name]  # Get the path of the selected model
         | 
| 13 | 
             
                print(f"Fetching model from: {model_path}")
         | 
| 14 |  | 
| 15 | 
             
                try:
         | 
| 16 | 
            +
                    # Dynamically load the model based on the selected model path
         | 
| 17 | 
            +
                    model = gr.load(model_path)  # Ensure this is the correct method to load your model
         | 
| 18 | 
            +
                    result_image = model(text)  # Generate the image from the input text
         | 
| 19 | 
            +
                    
         | 
| 20 | 
            +
                    # Ensure the result is in a proper image format
         | 
| 21 | 
            +
                    if isinstance(result_image, str):  # if model returns a path to the image
         | 
| 22 | 
            +
                        return gr.Image(result_image)
         | 
| 23 | 
            +
                    elif isinstance(result_image, bytes):  # if model returns raw image bytes
         | 
| 24 | 
            +
                        return gr.Image(value=result_image)
         | 
| 25 | 
            +
                    else:
         | 
| 26 | 
            +
                        return result_image
         | 
| 27 | 
             
                except Exception as e:
         | 
| 28 | 
             
                    print(f"Error loading model: {e}")
         | 
| 29 | 
             
                    return None
         | 
| 30 |  | 
| 31 | 
            +
            # Gradio Interface setup
         | 
| 32 | 
             
            interface = gr.Interface(
         | 
| 33 | 
             
                fn=generate_image,
         | 
| 34 | 
             
                inputs=[
         | 
| 35 | 
            +
                    gr.Textbox(label="Type here your imagination:", placeholder="Type your description here..."),  # Textbox for input
         | 
| 36 | 
            +
                    gr.Dropdown(label="Select Model", choices=list(models.keys()), value="Flux Lora")  # Dropdown for selecting the model
         | 
| 37 | 
             
                ],
         | 
| 38 | 
            +
                outputs=gr.Image(label="Generated Image"),  # Image output
         | 
| 39 | 
            +
                theme="NoCrypt/miku",  # Set theme for the interface
         | 
| 40 | 
             
                description="Sorry for the inconvenience. The model is currently running on the CPU, which might affect performance. We appreciate your understanding.",
         | 
| 41 | 
             
            )
         | 
| 42 |  | 
| 43 | 
            +
            # Launch the Gradio interface
         | 
| 44 | 
             
            interface.launch()
         | 
