Upload 2 files
Browse files- app (1).py +71 -0
- requirements (1).txt +2 -0
app (1).py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
# Initialize Gradio Client
|
| 6 |
+
client = Client("prithivMLmods/FireRed-Image-Edit-1.0-Fast")
|
| 7 |
+
|
| 8 |
+
# Define Prediction Function
|
| 9 |
+
def predict_image(images, prompt, seed, randomize_seed, guidance_scale, steps):
|
| 10 |
+
"""
|
| 11 |
+
Calls the external model's /infer endpoint using the Gradio client
|
| 12 |
+
and returns the prediction result.
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
images: Input image(s).
|
| 16 |
+
prompt: Text prompt for image editing.
|
| 17 |
+
seed: Random seed.
|
| 18 |
+
randomize_seed: Boolean to randomize seed.
|
| 19 |
+
guidance_scale: Guidance scale for the model.
|
| 20 |
+
steps: Number of inference steps.
|
| 21 |
+
|
| 22 |
+
Returns:
|
| 23 |
+
The prediction result from the model (e.g., an image).
|
| 24 |
+
"""
|
| 25 |
+
try:
|
| 26 |
+
result = client.predict(
|
| 27 |
+
images,
|
| 28 |
+
prompt,
|
| 29 |
+
seed,
|
| 30 |
+
randomize_seed,
|
| 31 |
+
guidance_scale,
|
| 32 |
+
steps,
|
| 33 |
+
api_name='/infer'
|
| 34 |
+
)
|
| 35 |
+
return result
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"Error during prediction: {e}")
|
| 38 |
+
return None
|
| 39 |
+
|
| 40 |
+
# Define input components
|
| 41 |
+
input_images = gr.Image(type="filepath", label="Input Image")
|
| 42 |
+
input_prompt = gr.Textbox(label="Prompt")
|
| 43 |
+
input_seed = gr.Slider(minimum=0, maximum=2147483647, step=1, label="Seed", value=0)
|
| 44 |
+
input_randomize_seed = gr.Checkbox(label="Randomize Seed", value=False)
|
| 45 |
+
input_guidance_scale = gr.Slider(minimum=0.0, maximum=20.0, step=0.1, label="Guidance Scale", value=7.5)
|
| 46 |
+
input_steps = gr.Slider(minimum=1, maximum=100, step=1, label="Inference Steps", value=20)
|
| 47 |
+
|
| 48 |
+
# Create a list of input components
|
| 49 |
+
input_components = [
|
| 50 |
+
input_images,
|
| 51 |
+
input_prompt,
|
| 52 |
+
input_seed,
|
| 53 |
+
input_randomize_seed,
|
| 54 |
+
input_guidance_scale,
|
| 55 |
+
input_steps
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
# Define the output component
|
| 59 |
+
output_image = gr.Image(label="Edited Image")
|
| 60 |
+
|
| 61 |
+
# Create the Gradio interface
|
| 62 |
+
iface = gr.Interface(
|
| 63 |
+
fn=predict_image,
|
| 64 |
+
inputs=input_components,
|
| 65 |
+
outputs=output_image,
|
| 66 |
+
title="FireRed Image Editor"
|
| 67 |
+
)
|
| 68 |
+
|
| 69 |
+
# Launch the Gradio app (optional for local testing, not needed for Spaces deployment if app.py is run directly)
|
| 70 |
+
if __name__ == "__main__":
|
| 71 |
+
iface.launch()
|
requirements (1).txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
gradio_client
|