Spaces:
Paused
Paused
Add remove output
Browse files
app.py
CHANGED
|
@@ -106,8 +106,8 @@ def detect_features(image_paths, garment_type, language="English"):
|
|
| 106 |
}
|
| 107 |
|
| 108 |
payload = {
|
| 109 |
-
|
| 110 |
-
"model": "gpt-4-turbo",
|
| 111 |
"messages": [
|
| 112 |
{
|
| 113 |
"role": "user",
|
|
@@ -120,6 +120,7 @@ def detect_features(image_paths, garment_type, language="English"):
|
|
| 120 |
Make sure to output the alt text in %s language.
|
| 121 |
If the photo does not contain a garment, return 'No garment detected'.
|
| 122 |
If the photo contains a garment, return the result in in the following JSON format without any preceding or trailing text:
|
|
|
|
| 123 |
{
|
| 124 |
"features": [list of comma separated features],
|
| 125 |
"intended_use": [list of comma separated intended uses],
|
|
@@ -184,7 +185,7 @@ def generate(*data):
|
|
| 184 |
messages = [
|
| 185 |
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites."""),
|
| 186 |
HumanMessage(content=f"""Write a product description with the following features.
|
| 187 |
-
Make sure that the description follows the structure of the reference structure.
|
| 188 |
Make sure to use markdown format for the output.
|
| 189 |
Make sure that the entire output is written entirely in language defined in the reference structure.
|
| 190 |
Use language that is suitable for the type of document specified in the reference structure.
|
|
@@ -212,7 +213,7 @@ def generate(*data):
|
|
| 212 |
return result_md, result_json
|
| 213 |
|
| 214 |
|
| 215 |
-
visible =
|
| 216 |
def add_output_click(*struct_ref):
|
| 217 |
global visible
|
| 218 |
print("Adding output ", visible)
|
|
@@ -227,6 +228,19 @@ def add_output_click(*struct_ref):
|
|
| 227 |
return struct_ref
|
| 228 |
|
| 229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
def show_advanced(model, temperature):
|
| 231 |
model = gr.Dropdown(models, value="gpt-4-turbo", interactive=True, label="Model", visible=True)
|
| 232 |
temperature = gr.Slider(minimum=0., maximum=1.0, value=0., interactive=True, label="Temperature", visible=True)
|
|
@@ -251,9 +265,12 @@ with gr.Blocks() as demo:
|
|
| 251 |
[gr.Textbox(label=f"Structure {i}", lines=10, value="", interactive=True, visible=i <= visible),
|
| 252 |
gr.Textbox(label=f"Reference copy {i}", lines=3, value="", interactive=True, visible=i <= visible)]]
|
| 253 |
struct_ref[0].value = structure_text_1
|
| 254 |
-
struct_ref[2].value = structure_text_2
|
| 255 |
-
|
| 256 |
-
|
|
|
|
|
|
|
|
|
|
| 257 |
with gr.Column():
|
| 258 |
md_output = gr.Markdown(label="Output", show_label=True)
|
| 259 |
json_output = gr.JSON(label="JSON Output")
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
payload = {
|
| 109 |
+
"model": "gpt-4o",
|
| 110 |
+
# "model": "gpt-4-turbo",
|
| 111 |
"messages": [
|
| 112 |
{
|
| 113 |
"role": "user",
|
|
|
|
| 120 |
Make sure to output the alt text in %s language.
|
| 121 |
If the photo does not contain a garment, return 'No garment detected'.
|
| 122 |
If the photo contains a garment, return the result in in the following JSON format without any preceding or trailing text:
|
| 123 |
+
|
| 124 |
{
|
| 125 |
"features": [list of comma separated features],
|
| 126 |
"intended_use": [list of comma separated intended uses],
|
|
|
|
| 185 |
messages = [
|
| 186 |
SystemMessage(content=f"""You are a helpful assistant that writes about products for ecommerce websites."""),
|
| 187 |
HumanMessage(content=f"""Write a product description with the following features.
|
| 188 |
+
Make sure that the description follows the structure of the reference structure.
|
| 189 |
Make sure to use markdown format for the output.
|
| 190 |
Make sure that the entire output is written entirely in language defined in the reference structure.
|
| 191 |
Use language that is suitable for the type of document specified in the reference structure.
|
|
|
|
| 213 |
return result_md, result_json
|
| 214 |
|
| 215 |
|
| 216 |
+
visible = 0
|
| 217 |
def add_output_click(*struct_ref):
|
| 218 |
global visible
|
| 219 |
print("Adding output ", visible)
|
|
|
|
| 228 |
return struct_ref
|
| 229 |
|
| 230 |
|
| 231 |
+
def remove_output_click(*struct_ref):
|
| 232 |
+
global visible
|
| 233 |
+
print("Removing output", visible)
|
| 234 |
+
visible -= 1
|
| 235 |
+
structure_texts = struct_ref[::2]
|
| 236 |
+
reference_texts = struct_ref[1::2]
|
| 237 |
+
structures = [gr.Textbox(label=f"Structure {i}", lines=10, value=structure_texts[i] if i <= visible else "", interactive=True, visible=i <= visible) for i in range(10)]
|
| 238 |
+
references = [gr.Textbox(label=f"Reference copy {i}", lines=3, value=reference_texts[i] if i <= visible else "", interactive=True, visible=i <= visible) for i in range(10)]
|
| 239 |
+
|
| 240 |
+
struct_ref = [val for pair in zip(structures, references) for val in pair]
|
| 241 |
+
return struct_ref
|
| 242 |
+
|
| 243 |
+
|
| 244 |
def show_advanced(model, temperature):
|
| 245 |
model = gr.Dropdown(models, value="gpt-4-turbo", interactive=True, label="Model", visible=True)
|
| 246 |
temperature = gr.Slider(minimum=0., maximum=1.0, value=0., interactive=True, label="Temperature", visible=True)
|
|
|
|
| 265 |
[gr.Textbox(label=f"Structure {i}", lines=10, value="", interactive=True, visible=i <= visible),
|
| 266 |
gr.Textbox(label=f"Reference copy {i}", lines=3, value="", interactive=True, visible=i <= visible)]]
|
| 267 |
struct_ref[0].value = structure_text_1
|
| 268 |
+
# struct_ref[2].value = structure_text_2
|
| 269 |
+
with gr.Row():
|
| 270 |
+
add_output = gr.Button(value="Add Output")
|
| 271 |
+
remove_output = gr.Button(value="Remove Output")
|
| 272 |
+
add_output.click(add_output_click, inputs=struct_ref, outputs=struct_ref)
|
| 273 |
+
remove_output.click(remove_output_click, inputs=struct_ref, outputs=struct_ref)
|
| 274 |
with gr.Column():
|
| 275 |
md_output = gr.Markdown(label="Output", show_label=True)
|
| 276 |
json_output = gr.JSON(label="JSON Output")
|