Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from openai import OpenAI
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
-
import os
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
# Initialize OpenAI client
|
| 9 |
-
client = OpenAI()
|
| 10 |
|
| 11 |
|
| 12 |
def array_to_image_path(image_array):
|
|
@@ -23,12 +23,13 @@ def array_to_image_path(image_array):
|
|
| 23 |
|
| 24 |
# Function to generate product description using OpenAI API
|
| 25 |
def generate_product_description(image, text_input=None):
|
| 26 |
-
# Convert the image to a path (
|
| 27 |
image_path = array_to_image_path(image)
|
| 28 |
|
| 29 |
-
#
|
| 30 |
-
#
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
# API request
|
| 34 |
completion = client.chat.completions.create(
|
|
@@ -74,5 +75,6 @@ with gr.Blocks(css=css) as demo:
|
|
| 74 |
generate_product_description, [input_img, text_input], [output_text]
|
| 75 |
)
|
| 76 |
|
|
|
|
| 77 |
demo.queue(api_open=False)
|
| 78 |
-
demo.launch(debug=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from openai import OpenAI
|
| 3 |
+
import os
|
| 4 |
from PIL import Image
|
| 5 |
import numpy as np
|
|
|
|
| 6 |
from datetime import datetime
|
| 7 |
|
| 8 |
# Initialize OpenAI client
|
| 9 |
+
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 10 |
|
| 11 |
|
| 12 |
def array_to_image_path(image_array):
|
|
|
|
| 23 |
|
| 24 |
# Function to generate product description using OpenAI API
|
| 25 |
def generate_product_description(image, text_input=None):
|
| 26 |
+
# Convert the image to a path (simulated handling)
|
| 27 |
image_path = array_to_image_path(image)
|
| 28 |
|
| 29 |
+
# Use a generated link from the Gradio app
|
| 30 |
+
# If share=True is set, the image will be available via a public URL
|
| 31 |
+
# Make sure the provided URL is accessible and correct in context
|
| 32 |
+
image_url = image_path # Replace this with actual URL when using Gradio's share functionality
|
| 33 |
|
| 34 |
# API request
|
| 35 |
completion = client.chat.completions.create(
|
|
|
|
| 75 |
generate_product_description, [input_img, text_input], [output_text]
|
| 76 |
)
|
| 77 |
|
| 78 |
+
# Set share=True to create a public URL
|
| 79 |
demo.queue(api_open=False)
|
| 80 |
+
demo.launch(debug=True, share=True)
|