| import gradio as gr |
| from gradio_client import Client |
| import re |
|
|
| |
| client = Client("selfit-camera/Omni-Image-Editor") |
|
|
| |
| def generate_image(prompt): |
| |
| result = client.predict( |
| prompt=prompt, |
| aspect_ratio="16:9", |
| api_name="/text_to_image_interface" |
| ) |
|
|
| |
| |
| html_string = result[0] |
| match = re.search(r"src='([^']+)'", html_string) |
| if match: |
| image_url = match.group(1) |
| return image_url |
| else: |
| |
| return "https://via.placeholder.com/400x200?text=Error:Image+Not+Found" |
|
|
| |
| with gr.Blocks(title='Omni Image Editor with Gradio') as demo: |
| gr.Markdown("## Omni Image Editor with Gradio") |
| with gr.Row(): |
| prompt_input = gr.Textbox(label='Enter your image prompt', placeholder='e.g., A futuristic city at sunset') |
| generate_btn = gr.Button("Generate Image") |
| output_image = gr.Image(label='Generated Image') |
|
|
| |
| generate_btn.click( |
| fn=generate_image, |
| inputs=[prompt_input], |
| outputs=[output_image] |
| ) |
|
|
| |
| demo.launch() |
| |