Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,9 @@ 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 |
-
|
|
|
|
|
36 |
client = OpenAI()
|
37 |
|
38 |
def process_chat(user_text):
|
@@ -41,9 +43,9 @@ def process_chat(user_text):
|
|
41 |
return
|
42 |
|
43 |
try:
|
44 |
-
# Use the client
|
45 |
response = client.chat.completions.create(
|
46 |
-
model="gpt-
|
47 |
messages=[
|
48 |
{"role": "system", "content": "You are a helpful assistant named Diane specializing in digital art advice."},
|
49 |
{"role": "user", "content": user_text},
|
@@ -53,8 +55,10 @@ def process_chat(user_text):
|
|
53 |
|
54 |
response_text = ""
|
55 |
for chunk in response:
|
56 |
-
|
57 |
-
|
|
|
|
|
58 |
response_text += token
|
59 |
yield response_text
|
60 |
|
|
|
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 |
|
40 |
def process_chat(user_text):
|
|
|
43 |
return
|
44 |
|
45 |
try:
|
46 |
+
# Use the OpenAI client for creating a chat completion
|
47 |
response = client.chat.completions.create(
|
48 |
+
model="gpt-4",
|
49 |
messages=[
|
50 |
{"role": "system", "content": "You are a helpful assistant named Diane specializing in digital art advice."},
|
51 |
{"role": "user", "content": user_text},
|
|
|
55 |
|
56 |
response_text = ""
|
57 |
for chunk in response:
|
58 |
+
# Extract the content correctly
|
59 |
+
delta = chunk.choices[0].delta # Get the delta object
|
60 |
+
if hasattr(delta, "content"): # Check if the delta has "content"
|
61 |
+
token = delta.content
|
62 |
response_text += token
|
63 |
yield response_text
|
64 |
|