ameerazam08 commited on
Commit
43fd88f
·
verified ·
1 Parent(s): 25ebc67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -69,24 +69,27 @@ def generate(text, file_name, api_key, model="gemini-2.0-flash-exp"):
69
 
70
  del files
71
  return temp_path
72
-
73
 
74
- def process_image_and_prompt(composite_pil, prompt, gemini_api_key):
75
- # Save the composite image to a temporary file.
76
- with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
77
- composite_path = tmp.name
78
- composite_pil.save(composite_path)
79
 
80
- file_name = composite_path
81
- input_text = prompt
82
- model = "gemini-2.0-flash-exp"
83
-
84
- gemma_edited_image_path = generate(text=input_text, file_name=file_name, api_key=gemini_api_key, model=model)
85
- print("image_path ", gemma_edited_image_path)
86
- result_img = Image.open(gemma_edited_image_path)
87
- if result_img.mode == "RGBA":
88
- result_img = result_img.convert("RGB")
89
- return [result_img]
 
 
 
 
 
 
 
 
 
90
 
91
  # Build a Blocks-based interface to include the custom HTML header.
92
  with gr.Blocks() as demo:
@@ -163,4 +166,4 @@ with gr.Blocks() as demo:
163
  label="Try these examples"
164
  )
165
 
166
- demo.launch(share=True)
 
69
 
70
  del files
71
  return temp_path
 
72
 
 
 
 
 
 
73
 
74
+ def process_image_and_prompt(composite_pil, prompt, gemini_api_key):
75
+ try:
76
+ # Save the composite image to a temporary file.
77
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp:
78
+ composite_path = tmp.name
79
+ composite_pil.save(composite_path)
80
+
81
+ file_name = composite_path
82
+ input_text = prompt
83
+ model = "gemini-2.0-flash-exp"
84
+
85
+ gemma_edited_image_path = generate(text=input_text, file_name=file_name, api_key=gemini_api_key, model=model)
86
+ print("image_path ", gemma_edited_image_path)
87
+ result_img = Image.open(gemma_edited_image_path)
88
+ if result_img.mode == "RGBA":
89
+ result_img = result_img.convert("RGB")
90
+ return [result_img]
91
+ except Exception as e:
92
+ raise gr.Error(f"Error Getting {e}", duration=5)
93
 
94
  # Build a Blocks-based interface to include the custom HTML header.
95
  with gr.Blocks() as demo:
 
166
  label="Try these examples"
167
  )
168
 
169
+ demo.queue(max_size=500).launch()