drdudddd commited on
Commit
dd16cb5
·
verified ·
1 Parent(s): 433b15c

Upload app (2).py

Browse files
Files changed (1) hide show
  1. app (2).py +73 -0
app (2).py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Ensure images is always a list, even if only one image is provided
27
+ images_list = [images] if not isinstance(images, list) else images
28
+ result = client.predict(
29
+ images_list,
30
+ prompt,
31
+ seed,
32
+ randomize_seed,
33
+ guidance_scale,
34
+ steps,
35
+ api_name='/infer'
36
+ )
37
+ return result
38
+ except Exception as e:
39
+ print(f"Error during prediction: {e}")
40
+ return None
41
+
42
+ # Define input components
43
+ input_images = gr.Image(type="filepath", label="Input Image")
44
+ input_prompt = gr.Textbox(label="Prompt")
45
+ input_seed = gr.Slider(minimum=0, maximum=2147483647, step=1, label="Seed", value=0)
46
+ input_randomize_seed = gr.Checkbox(label="Randomize Seed", value=False)
47
+ input_guidance_scale = gr.Slider(minimum=0.0, maximum=20.0, step=0.1, label="Guidance Scale", value=7.5)
48
+ input_steps = gr.Slider(minimum=1, maximum=100, step=1, label="Inference Steps", value=20)
49
+
50
+ # Create a list of input components
51
+ input_components = [
52
+ input_images,
53
+ input_prompt,
54
+ input_seed,
55
+ input_randomize_seed,
56
+ input_guidance_scale,
57
+ input_steps
58
+ ]
59
+
60
+ # Define the output component
61
+ output_image = gr.Image(label="Edited Image")
62
+
63
+ # Create the Gradio interface
64
+ iface = gr.Interface(
65
+ fn=predict_image,
66
+ inputs=input_components,
67
+ outputs=output_image,
68
+ title="FireRed Image Editor"
69
+ )
70
+
71
+ # Launch the Gradio app (optional for local testing, not needed for Spaces deployment if app.py is run directly)
72
+ if __name__ == "__main__":
73
+ iface.launch()