5 / app.py
drdudddd's picture
Rename app (2).py to app.py
931d34a verified
from gradio_client import Client
import gradio as gr
# Initialize Gradio Client
client = Client("prithivMLmods/FireRed-Image-Edit-1.0-Fast")
# Define Prediction Function
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:
# Ensure images is always a list, even if only one image is provided
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
# Define input components
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)
# Create a list of input components
input_components = [
input_images,
input_prompt,
input_seed,
input_randomize_seed,
input_guidance_scale,
input_steps
]
# Define the output component
output_image = gr.Image(label="Edited Image")
# Create the Gradio interface
iface = gr.Interface(
fn=predict_image,
inputs=input_components,
outputs=output_image,
title="FireRed Image Editor"
)
# Launch the Gradio app (optional for local testing, not needed for Spaces deployment if app.py is run directly)
if __name__ == "__main__":
iface.launch()