Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,8 +32,6 @@ object_labels = [
|
|
32 |
EXAMPLE_IMAGE_URL = "https://www.watercoloraffair.com/wp-content/uploads/2023/04/monet-houses-of-parliament-low-key.jpg" # Square example image
|
33 |
example_image = Image.open(BytesIO(requests.get(EXAMPLE_IMAGE_URL).content))
|
34 |
|
35 |
-
from openai import OpenAI
|
36 |
-
|
37 |
# Initialize the OpenAI client
|
38 |
client = OpenAI()
|
39 |
|
@@ -45,7 +43,7 @@ def process_chat(user_text):
|
|
45 |
try:
|
46 |
# Use the OpenAI client for creating a chat completion
|
47 |
response = client.chat.completions.create(
|
48 |
-
model="gpt-
|
49 |
messages=[
|
50 |
{"role": "system", "content": "You are a helpful assistant named Diane specializing in digital art advice."},
|
51 |
{"role": "user", "content": user_text},
|
@@ -57,8 +55,8 @@ def process_chat(user_text):
|
|
57 |
for chunk in response:
|
58 |
# Extract the content correctly
|
59 |
delta = chunk.choices[0].delta # Get the delta object
|
60 |
-
|
61 |
-
|
62 |
response_text += token
|
63 |
yield response_text
|
64 |
|
@@ -66,7 +64,6 @@ def process_chat(user_text):
|
|
66 |
yield f"❌ An error occurred: {str(e)}"
|
67 |
|
68 |
|
69 |
-
|
70 |
# Function to analyze image contrast
|
71 |
def analyze_contrast_opencv(image_path):
|
72 |
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|
|
|
32 |
EXAMPLE_IMAGE_URL = "https://www.watercoloraffair.com/wp-content/uploads/2023/04/monet-houses-of-parliament-low-key.jpg" # Square example image
|
33 |
example_image = Image.open(BytesIO(requests.get(EXAMPLE_IMAGE_URL).content))
|
34 |
|
|
|
|
|
35 |
# Initialize the OpenAI client
|
36 |
client = OpenAI()
|
37 |
|
|
|
43 |
try:
|
44 |
# Use the OpenAI client for creating a chat completion
|
45 |
response = client.chat.completions.create(
|
46 |
+
model="gpt-4o-mini",
|
47 |
messages=[
|
48 |
{"role": "system", "content": "You are a helpful assistant named Diane specializing in digital art advice."},
|
49 |
{"role": "user", "content": user_text},
|
|
|
55 |
for chunk in response:
|
56 |
# Extract the content correctly
|
57 |
delta = chunk.choices[0].delta # Get the delta object
|
58 |
+
token = getattr(delta, "content", None) # Safely get the "content" field
|
59 |
+
if token: # Only process non-None tokens
|
60 |
response_text += token
|
61 |
yield response_text
|
62 |
|
|
|
64 |
yield f"❌ An error occurred: {str(e)}"
|
65 |
|
66 |
|
|
|
67 |
# Function to analyze image contrast
|
68 |
def analyze_contrast_opencv(image_path):
|
69 |
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
|