Spaces:
Sleeping
Sleeping
Arjun Singh
commited on
Commit
·
7aa357c
1
Parent(s):
83dea57
reverted to original
Browse files
app.py
CHANGED
|
@@ -38,22 +38,20 @@ def call_api_and_generate_image(negative_prompt, positive_prompt,seed, source_im
|
|
| 38 |
)
|
| 39 |
|
| 40 |
result = resp.json()
|
| 41 |
-
|
| 42 |
-
image_data = base64.b64decode(
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
return image_output
|
| 46 |
|
| 47 |
def generate_image(positive_prompt, negative_prompt,source_image):
|
| 48 |
seed = numpy.random.randint(0, 2**32 - 1)
|
| 49 |
try:
|
| 50 |
-
|
| 51 |
-
return image_output,""
|
| 52 |
except Exception as e:
|
| 53 |
return None, f"Error: {str(e)}"
|
| 54 |
|
| 55 |
def clear_fields():
|
| 56 |
-
return "", "", None # Clear prompt and outputs
|
| 57 |
|
| 58 |
with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
|
| 59 |
gr.Markdown("<center><h2>Arjun's Image Generator</h2></center>")
|
|
@@ -67,8 +65,8 @@ with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
|
|
| 67 |
clear_btn = gr.ClearButton(value="Clear Question and AI Response", elem_id="clear_button", variant="secondary", size="sm")
|
| 68 |
gr.Markdown("<center><h3>AI Response</h3></center>")
|
| 69 |
image_output_box = gr.Image(type="pil", label="Final Generated Image")
|
| 70 |
-
|
| 71 |
-
submit_btn.click(fn=generate_image, inputs = [prompt,neg_prompt,source_image], outputs=[image_output_box])
|
| 72 |
-
clear_btn.click(fn=clear_fields,outputs=[prompt,neg_prompt,image_output_box])
|
| 73 |
|
| 74 |
demo.launch()
|
|
|
|
| 38 |
)
|
| 39 |
|
| 40 |
result = resp.json()
|
| 41 |
+
base64_data = result['result'][0]['data']
|
| 42 |
+
image_data = base64.b64decode(base64_data)
|
| 43 |
+
image = Image.open(io.BytesIO(image_data))
|
| 44 |
+
return image, json.dumps(result, indent=2)
|
|
|
|
| 45 |
|
| 46 |
def generate_image(positive_prompt, negative_prompt,source_image):
|
| 47 |
seed = numpy.random.randint(0, 2**32 - 1)
|
| 48 |
try:
|
| 49 |
+
return call_api_and_generate_image(negative_prompt, positive_prompt,seed,source_image)
|
|
|
|
| 50 |
except Exception as e:
|
| 51 |
return None, f"Error: {str(e)}"
|
| 52 |
|
| 53 |
def clear_fields():
|
| 54 |
+
return "", "", None,"" # Clear prompt and outputs
|
| 55 |
|
| 56 |
with gr.Blocks(theme='freddyaboulton/test-blue') as demo:
|
| 57 |
gr.Markdown("<center><h2>Arjun's Image Generator</h2></center>")
|
|
|
|
| 65 |
clear_btn = gr.ClearButton(value="Clear Question and AI Response", elem_id="clear_button", variant="secondary", size="sm")
|
| 66 |
gr.Markdown("<center><h3>AI Response</h3></center>")
|
| 67 |
image_output_box = gr.Image(type="pil", label="Final Generated Image")
|
| 68 |
+
json_output = gr.Textbox(label="API Response JSON", lines=10)
|
| 69 |
+
submit_btn.click(fn=generate_image, inputs = [prompt,neg_prompt,source_image], outputs=[image_output_box,json_output])
|
| 70 |
+
clear_btn.click(fn=clear_fields,outputs=[prompt,neg_prompt,image_output_box,json_output])
|
| 71 |
|
| 72 |
demo.launch()
|