miaw1419 commited on
Commit
2b0ebe1
·
verified ·
1 Parent(s): a6166d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -42,8 +42,8 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
42
  device = "cuda" if torch.cuda.is_available() else "cpu"
43
 
44
 
45
- word_list_dataset = load_dataset("EPFL-VILAB/4m-wordlist", data_files="list.txt", use_auth_token=True)
46
- word_list = word_list_dataset["train"]['text']
47
 
48
  bnb_config = BitsAndBytesConfig(
49
  load_in_4bit=True,
@@ -255,6 +255,8 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
255
 
256
  clear_botton = gr.Button("Clear comments", interactive=len(comments) != 0)
257
 
 
 
258
  return (gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True),
259
  gr.Text(label="Comment", show_label=False, lines=4, max_lines=5, placeholder="Enter your comment. The more detailed the better.", value=next_comment, container=False),
260
  gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) >= 5, variant="primary"),
@@ -301,9 +303,9 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
301
  if len(comments) < 8:
302
  gr.Warning("Fewer than 8 comments may lead to errors.")
303
 
304
- keys = list(comments.keys())
305
- random.shuffle(keys)
306
- comments = dict([(key, comments[key]) for key in keys])
307
 
308
  prompt = """I will provide a set of artworks along with accompanying comments from a person. Analyze these artworks and the comments on them and identify artistic features such as present or mentioned colors, style, composition, mood, medium, texture, brushwork, lighting, shadow effects, perspective, and other noteworthy elements.
309
  Your task is to extract the artistic features the person likes and dislikes based on both the artworks' features and the person's comments. Focus solely on artistic aspects and refrain from considering subject matter.
@@ -344,6 +346,8 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
344
  generated_ids = vpe_model.generate(**inputs, max_new_tokens=2000, repetition_penalty=0.99, do_sample=False)
345
  generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
346
 
 
 
347
  if re.match(r"(.|\n)*Assistant: Liked Art Features: (.|\n)*Disliked Art Features: (.|\n)*", generated_texts):
348
  positive_vp, negative_vp = re.search('.* \nAssistant: Liked Art Features: (.*)\nDisliked Art Features: (.*)', generated_texts).groups()
349
  positive_vp = positive_vp.split(", ")
@@ -505,11 +509,11 @@ with gr.Blocks(css=css, title="ViPer Demo", theme=gr.themes.Base()) as demo:
505
  if vp_pos == "" and vp_neg == "":
506
  slider = 0
507
 
508
- for filter in word_list:
509
- if re.search(rf"\b{filter}\b", prompt):
510
- raise gr.Error("Please try again with a different prompt")
511
- if re.search(rf"\b{filter}\b", vp_pos) or re.search(rf"\b{filter}\b", vp_neg):
512
- raise gr.Error("Please try again with a different visual preference")
513
 
514
  if vp_pos != "":
515
  vp_pos = vp_pos.split(", ")
 
42
  device = "cuda" if torch.cuda.is_available() else "cpu"
43
 
44
 
45
+ #word_list_dataset = load_dataset("EPFL-VILAB/4m-wordlist", data_files="list.txt", use_auth_token=True)
46
+ #word_list = word_list_dataset["train"]['text']
47
 
48
  bnb_config = BitsAndBytesConfig(
49
  load_in_4bit=True,
 
255
 
256
  clear_botton = gr.Button("Clear comments", interactive=len(comments) != 0)
257
 
258
+ print(comments)
259
+
260
  return (gr.Image(value=comment_images[0], label=f"image {image_index+1}/{len(comment_images)}", show_label=True),
261
  gr.Text(label="Comment", show_label=False, lines=4, max_lines=5, placeholder="Enter your comment. The more detailed the better.", value=next_comment, container=False),
262
  gr.Button(f"Extract visual preference from {len(comments)} comments", interactive=len(comments) >= 5, variant="primary"),
 
303
  if len(comments) < 8:
304
  gr.Warning("Fewer than 8 comments may lead to errors.")
305
 
306
+ #keys = list(comments.keys())
307
+ #random.shuffle(keys)
308
+ #comments = dict([(key, comments[key]) for key in keys])
309
 
310
  prompt = """I will provide a set of artworks along with accompanying comments from a person. Analyze these artworks and the comments on them and identify artistic features such as present or mentioned colors, style, composition, mood, medium, texture, brushwork, lighting, shadow effects, perspective, and other noteworthy elements.
311
  Your task is to extract the artistic features the person likes and dislikes based on both the artworks' features and the person's comments. Focus solely on artistic aspects and refrain from considering subject matter.
 
346
  generated_ids = vpe_model.generate(**inputs, max_new_tokens=2000, repetition_penalty=0.99, do_sample=False)
347
  generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=True)[0]
348
 
349
+ print(generated_texts)
350
+
351
  if re.match(r"(.|\n)*Assistant: Liked Art Features: (.|\n)*Disliked Art Features: (.|\n)*", generated_texts):
352
  positive_vp, negative_vp = re.search('.* \nAssistant: Liked Art Features: (.*)\nDisliked Art Features: (.*)', generated_texts).groups()
353
  positive_vp = positive_vp.split(", ")
 
509
  if vp_pos == "" and vp_neg == "":
510
  slider = 0
511
 
512
+ #for filter in word_list:
513
+ # if re.search(rf"\b{filter}\b", prompt):
514
+ # raise gr.Error("Please try again with a different prompt")
515
+ # if re.search(rf"\b{filter}\b", vp_pos) or re.search(rf"\b{filter}\b", vp_neg):
516
+ # raise gr.Error("Please try again with a different visual preference")
517
 
518
  if vp_pos != "":
519
  vp_pos = vp_pos.split(", ")