Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import spaces
|
| 3 |
import requests
|
|
@@ -6,14 +7,19 @@ import gradio as gr
|
|
| 6 |
from PIL import Image
|
| 7 |
from io import BytesIO
|
| 8 |
from turtle import title
|
| 9 |
-
from
|
| 10 |
-
import ast
|
| 11 |
from collections import Counter
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
pipe = pipeline("zero-shot-image-classification", model="patrickjohncyh/fashion-clip")
|
| 14 |
|
| 15 |
color_file_path = 'color_config.json'
|
| 16 |
attributes_file_path = 'attributes_config.json'
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Open and read the COLOR JSON file
|
| 19 |
with open(color_file_path, 'r') as file:
|
|
@@ -36,7 +42,8 @@ def shot(input, category):
|
|
| 36 |
"sub":subColour,
|
| 37 |
"score":round(score*100,2)
|
| 38 |
},
|
| 39 |
-
"attributes":common_result
|
|
|
|
| 40 |
}
|
| 41 |
|
| 42 |
|
|
@@ -119,7 +126,7 @@ def get_openAI_tags(image_urls):
|
|
| 119 |
for image in image_urls:
|
| 120 |
imageList.append({"type": "image_url", "image_url": {"url": image}})
|
| 121 |
|
| 122 |
-
|
| 123 |
model="gpt-4o",
|
| 124 |
messages=[
|
| 125 |
{
|
|
@@ -142,6 +149,8 @@ def get_openAI_tags(image_urls):
|
|
| 142 |
frequency_penalty=0,
|
| 143 |
presence_penalty=0
|
| 144 |
)
|
|
|
|
|
|
|
| 145 |
|
| 146 |
# Define the Gradio interface with the updated components
|
| 147 |
iface = gr.Interface(
|
|
|
|
| 1 |
+
import ast
|
| 2 |
import json
|
| 3 |
import spaces
|
| 4 |
import requests
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
from io import BytesIO
|
| 9 |
from turtle import title
|
| 10 |
+
from openai import OpenAI
|
|
|
|
| 11 |
from collections import Counter
|
| 12 |
+
from transformers import pipeline
|
| 13 |
+
|
| 14 |
+
client = OpenAI()
|
| 15 |
|
| 16 |
pipe = pipeline("zero-shot-image-classification", model="patrickjohncyh/fashion-clip")
|
| 17 |
|
| 18 |
color_file_path = 'color_config.json'
|
| 19 |
attributes_file_path = 'attributes_config.json'
|
| 20 |
+
import os
|
| 21 |
+
OPENAIKEY = os.getenv("OPENAI_KEY")
|
| 22 |
+
|
| 23 |
|
| 24 |
# Open and read the COLOR JSON file
|
| 25 |
with open(color_file_path, 'r') as file:
|
|
|
|
| 42 |
"sub":subColour,
|
| 43 |
"score":round(score*100,2)
|
| 44 |
},
|
| 45 |
+
"attributes":common_result,
|
| 46 |
+
"image_mapping":openai_parsed_response
|
| 47 |
}
|
| 48 |
|
| 49 |
|
|
|
|
| 126 |
for image in image_urls:
|
| 127 |
imageList.append({"type": "image_url", "image_url": {"url": image}})
|
| 128 |
|
| 129 |
+
openai_response = client.chat.completions.create(
|
| 130 |
model="gpt-4o",
|
| 131 |
messages=[
|
| 132 |
{
|
|
|
|
| 149 |
frequency_penalty=0,
|
| 150 |
presence_penalty=0
|
| 151 |
)
|
| 152 |
+
response= json.loads(openai_response.choices[0].message.content)
|
| 153 |
+
return response
|
| 154 |
|
| 155 |
# Define the Gradio interface with the updated components
|
| 156 |
iface = gr.Interface(
|