| |
|
| | from gradio_client import Client |
| | import gradio as gr |
| |
|
| | |
| | client = Client("prithivMLmods/FireRed-Image-Edit-1.0-Fast") |
| |
|
| | |
| | def predict_image(images, prompt, seed, randomize_seed, guidance_scale, steps): |
| | """ |
| | Calls the external model's /infer endpoint using the Gradio client |
| | and returns the prediction result. |
| | |
| | Args: |
| | images: Input image(s). |
| | prompt: Text prompt for image editing. |
| | seed: Random seed. |
| | randomize_seed: Boolean to randomize seed. |
| | guidance_scale: Guidance scale for the model. |
| | steps: Number of inference steps. |
| | |
| | Returns: |
| | The prediction result from the model (e.g., an image). |
| | """ |
| | try: |
| | |
| | images_list = [images] if not isinstance(images, list) else images |
| | result = client.predict( |
| | images_list, |
| | prompt, |
| | seed, |
| | randomize_seed, |
| | guidance_scale, |
| | steps, |
| | api_name='/infer' |
| | ) |
| | return result |
| | except Exception as e: |
| | print(f"Error during prediction: {e}") |
| | return None |
| |
|
| | |
| | input_images = gr.Image(type="filepath", label="Input Image") |
| | input_prompt = gr.Textbox(label="Prompt") |
| | input_seed = gr.Slider(minimum=0, maximum=2147483647, step=1, label="Seed", value=0) |
| | input_randomize_seed = gr.Checkbox(label="Randomize Seed", value=False) |
| | input_guidance_scale = gr.Slider(minimum=0.0, maximum=20.0, step=0.1, label="Guidance Scale", value=7.5) |
| | input_steps = gr.Slider(minimum=1, maximum=100, step=1, label="Inference Steps", value=20) |
| |
|
| | |
| | input_components = [ |
| | input_images, |
| | input_prompt, |
| | input_seed, |
| | input_randomize_seed, |
| | input_guidance_scale, |
| | input_steps |
| | ] |
| |
|
| | |
| | output_image = gr.Image(label="Edited Image") |
| |
|
| | |
| | iface = gr.Interface( |
| | fn=predict_image, |
| | inputs=input_components, |
| | outputs=output_image, |
| | title="FireRed Image Editor" |
| | ) |
| |
|
| | |
| | if __name__ == "__main__": |
| | iface.launch() |
| |
|