Add initial implementation for AI Background Replacement app
Browse files- Create main application file with image processing functionality
- Add Gradio interface for user interaction
- Include example images for demonstration
- Set up .gitignore to exclude environment variables
- Define project dependencies in requirements.txt
- .gitignore +1 -0
- app.py +56 -0
- examples/.gitkeep +0 -0
- examples/person_hills.jpg +0 -0
- examples/person_street.jpg +0 -0
- examples/person_wall.jpg +0 -0
- requirements.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.env
|
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import fal_client
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import requests
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
def process_image(image, prompt):
|
| 9 |
+
image_url = fal_client.upload_file(image)
|
| 10 |
+
arguments = {
|
| 11 |
+
"image_url": image_url,
|
| 12 |
+
"prompt": prompt
|
| 13 |
+
}
|
| 14 |
+
handler = fal_client.submit(
|
| 15 |
+
"workflows/acemetrics/bgrep",
|
| 16 |
+
arguments=arguments
|
| 17 |
+
)
|
| 18 |
+
result = fal_client.result("workflows/acemetrics/bgrep", handler.request_id)
|
| 19 |
+
result_url = result['images'][0]['url']
|
| 20 |
+
response = requests.get(result_url)
|
| 21 |
+
temp_output = "temp_output.png"
|
| 22 |
+
with open(temp_output, "wb") as f:
|
| 23 |
+
f.write(response.content)
|
| 24 |
+
|
| 25 |
+
return temp_output
|
| 26 |
+
|
| 27 |
+
with gr.Blocks(title="AI Background Replacement") as demo:
|
| 28 |
+
|
| 29 |
+
with gr.Row():
|
| 30 |
+
with gr.Column():
|
| 31 |
+
image_input = gr.Image(label="Upload Image", type="filepath")
|
| 32 |
+
prompt_input = gr.Textbox(label="Background Prompt", lines=2)
|
| 33 |
+
process_btn = gr.Button("Replace Background", variant="primary")
|
| 34 |
+
|
| 35 |
+
with gr.Column():
|
| 36 |
+
output_image = gr.Image(label="Result")
|
| 37 |
+
|
| 38 |
+
gr.Examples(
|
| 39 |
+
examples=[
|
| 40 |
+
["examples/person_hills.jpg", "Snow-covered Alps mountains with falling snow"],
|
| 41 |
+
["examples/person_wall.jpg", "Dense forest with trees and natural lighting"],
|
| 42 |
+
["examples/person_street.jpg", "Serene ocean beach with soft waves"],
|
| 43 |
+
],
|
| 44 |
+
inputs=[image_input, prompt_input],
|
| 45 |
+
fn=process_image,
|
| 46 |
+
outputs=output_image,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
process_btn.click(
|
| 50 |
+
fn=process_image,
|
| 51 |
+
inputs=[image_input, prompt_input],
|
| 52 |
+
outputs=output_image
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
demo.launch()
|
examples/.gitkeep
ADDED
|
File without changes
|
examples/person_hills.jpg
ADDED
|
examples/person_street.jpg
ADDED
|
examples/person_wall.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
fal-client
|
| 3 |
+
python-dotenv
|
| 4 |
+
requests
|