Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,37 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
def con_image(image1):
|
| 5 |
-
im1 = Image.open(image1)
|
| 6 |
-
im1.save(r'new_name.png')
|
| 7 |
-
return im1
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import base64
|
| 3 |
+
import requests
|
| 4 |
+
import tempfile
|
| 5 |
+
import os
|
| 6 |
+
import openai import OpenAI
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
# def con_image(image1):
|
| 10 |
+
# im1 = Image.open(image1)
|
| 11 |
+
# im1.save(r'new_name.png')
|
| 12 |
+
# return im1
|
| 13 |
+
def create_var(image_path)
|
| 14 |
+
client = OpenAI(api_key = "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")
|
| 15 |
+
# image2 = con_image("white_tile.jpg")
|
| 16 |
+
response = client.images.create_variation(
|
| 17 |
+
image=open(image_path, "rb"),
|
| 18 |
+
n=1,
|
| 19 |
+
size="1024x1024"
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
image_url = response.data[0].url
|
| 23 |
+
# print(response.data[0])
|
| 24 |
+
return(image_url)
|
| 25 |
|
| 26 |
+
block = gr.Blocks(theme=gr.themes.Glass(primary_hue="slate"))
|
| 27 |
+
with block:
|
| 28 |
+
gr.Markdown("""<h1><center>Visual Explorer - Ask and Learn about Images</center></h1> """)
|
| 29 |
+
with gr.Row():
|
| 30 |
+
with gr.Column(scale=0.5):
|
| 31 |
+
img_input = gr.Image(type="filepath", label="Upload Image")
|
| 32 |
+
api_input = gr.Textbox(label= "Enter Api-key")
|
| 33 |
+
upload_button = gr.Button(value="Upload & Start Chat", interactive=True, variant="primary")
|
| 34 |
+
with gr.Column():
|
| 35 |
+
text = gr.Textbox(label="Output")
|
| 36 |
+
upload_button.click(create_var, inputs=[img_input, api_input], outputs=[text])
|
| 37 |
+
block.launch()
|