tunght commited on
Commit
74d4b47
·
1 Parent(s): eb3c692

add garment type

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -34,6 +34,8 @@ features = "Brand: Duckly. \nProduct name: Duck runner pro. \nKey properties: t-
34
 
35
  reference = " "
36
 
 
 
37
  import base64
38
  import requests
39
 
@@ -59,13 +61,15 @@ def get_json(text: str):
59
  return json.loads(text)
60
 
61
 
62
- def detect_features(image_paths):
63
  # Path to your image
64
  # image_path = "path_to_your_image.jpg"
65
 
66
  # Getting the base64 string
67
  try:
68
  base64_images = [encode_image(image_path[0]) for image_path in image_paths]
 
 
69
 
70
  headers = {
71
  "Content-Type": "application/json",
@@ -80,8 +84,8 @@ def detect_features(image_paths):
80
  "content": [
81
  {
82
  "type": "text",
83
- "text": """Describe the features of the garment in the photos in less than 100 words.
84
- What is the intended use of the garment in this image, use at most 5 words for intended use?
85
  Generate alt text for each of the images.
86
  If the photo does not contain a garment, return 'No garment detected'.
87
  If the photo contains a garment, return the result in in the following JSON format without any preceding or trailing text:
@@ -115,9 +119,9 @@ def detect_features(image_paths):
115
  return "", []
116
 
117
 
118
- def generate(features, image, structure, reference, model, temperature):
119
  print(f"features {features},\n image {image},\n structure{structure},\n model{model},\n temperature {temperature},\n reference {reference}")
120
- image_features, base64_images = detect_features(image)
121
  detected_features = ""
122
  intended_use = ""
123
  alt_texts = []
@@ -149,6 +153,7 @@ demo = gr.Interface(
149
  fn=generate,
150
  inputs=[gr.Textbox(features, label="Features"),
151
  gr.Gallery(label="Product image(s)", type="filepath"),
 
152
  gr.Textbox(structure, label="Structure"),
153
  gr.Textbox(reference, label="Reference copy"),
154
  gr.Dropdown(["gpt-4-turbo", "gpt-3.5-turbo", "claude-3-sonnet-20240229", "claude-3-opus-20240229", "llama3-70b-8192"], value="llama3-70b-8192", label="Model"),
 
34
 
35
  reference = " "
36
 
37
+ garment_type = "all"
38
+
39
  import base64
40
  import requests
41
 
 
61
  return json.loads(text)
62
 
63
 
64
+ def detect_features(image_paths, garment_type):
65
  # Path to your image
66
  # image_path = "path_to_your_image.jpg"
67
 
68
  # Getting the base64 string
69
  try:
70
  base64_images = [encode_image(image_path[0]) for image_path in image_paths]
71
+ if garment_type == "" or garment_type == "all":
72
+ garment_type = "garment"
73
 
74
  headers = {
75
  "Content-Type": "application/json",
 
84
  "content": [
85
  {
86
  "type": "text",
87
+ "text": """Describe the features of the {garment_type} in the photos in less than 100 words.
88
+ What is the intended use of the {garment_type} in this image, use at most 5 words for intended use?
89
  Generate alt text for each of the images.
90
  If the photo does not contain a garment, return 'No garment detected'.
91
  If the photo contains a garment, return the result in in the following JSON format without any preceding or trailing text:
 
119
  return "", []
120
 
121
 
122
+ def generate(features, image, garment_type, structure, reference, model, temperature):
123
  print(f"features {features},\n image {image},\n structure{structure},\n model{model},\n temperature {temperature},\n reference {reference}")
124
+ image_features, base64_images = detect_features(image, garment_type)
125
  detected_features = ""
126
  intended_use = ""
127
  alt_texts = []
 
153
  fn=generate,
154
  inputs=[gr.Textbox(features, label="Features"),
155
  gr.Gallery(label="Product image(s)", type="filepath"),
156
+ gr.Textbox(garment_type, label="Garment type"),
157
  gr.Textbox(structure, label="Structure"),
158
  gr.Textbox(reference, label="Reference copy"),
159
  gr.Dropdown(["gpt-4-turbo", "gpt-3.5-turbo", "claude-3-sonnet-20240229", "claude-3-opus-20240229", "llama3-70b-8192"], value="llama3-70b-8192", label="Model"),