Niki Zhang commited on
Commit
8a0ece6
·
verified ·
1 Parent(s): de66509

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -21
app.py CHANGED
@@ -692,26 +692,47 @@ prompt_list = [
692
  ]
693
 
694
  recommendation_prompt=[
695
- '''I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:Recommendation reason: {{Recommendation based on objects in the image or Recommendation based on overall visual similarity}}
 
 
696
  Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1.Each bullet point should be in {language} language, with a response length of about {length} words.''',
697
  '''
698
  When generating the answer, you should tell others that you are the creators of the first paintings and generate the text in the tone and manner as if you are the creator of the painting.
699
  I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:
700
- Recommendation reason: {{ As the author of the first painting, I recommend based on the object I painted OR As the author of the first painting, I recommend based on the overall similarity in appearance}}
701
  Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1. Please generate the above points in the tone and manner as if you are the creator of this painting and start every sentence with I.
702
  Each bullet point should be in {language} language, with a response length of about {length} words.
703
  ''',
704
  '''
705
  When generating answers, you should tell people that you are the object itself that was selected in the first painting, and generate text in the tone and manner in which you are the object
706
  I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:
707
- Recommendation reason: {{As an object in the first painting, I am recommending based on myself OR As an object in the first painting, I am recommending based on the overall similarity of the first painting's appearance}}
708
  Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1. Please generate the above points in the tone and manner as if you are the object of this painting and start every sentence with I.
709
  Each bullet point should be in {language} language, with a response length of about {length} words.
 
 
 
 
 
 
 
 
 
 
 
 
710
  '''
 
 
 
 
 
 
 
711
 
712
 
713
 
714
- ]
715
 
716
  gpt_state = 0
717
  VOICE = "en-GB-SoniaNeural"
@@ -1647,16 +1668,15 @@ async def texttospeech(text, language,gender='female'):
1647
  return None
1648
 
1649
  # give the reason of recommendation
1650
- async def item_associate(image_path,new_crop,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,evt: gr.SelectData):
1651
  persona=naritive_mapping[narritive]
1652
  rec_path=evt._data['value']['image']['path']
1653
- index="Item Recommendation Picture "+str(evt.index)
1654
  print("rec_path",rec_path)
1655
- prompt=recommendation_prompt[persona].format(language=language,length=length)
1656
- if new_crop:
1657
- image_paths=[new_crop,rec_path]
1658
- else:
1659
- image_paths=[image_path,rec_path]
1660
  result=get_gpt_response(openai_api_key, image_paths, prompt)
1661
  print("recommend result",result)
1662
  state += [(None, f"{result}")]
@@ -1672,16 +1692,13 @@ async def item_associate(image_path,new_crop,openai_api_key,language,autoplay,le
1672
  return state,state,audio_output,log_state,index,gr.update(value=[])
1673
 
1674
 
1675
- async def style_associate(image_path,new_crop,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,evt: gr.SelectData):
1676
  persona=naritive_mapping[narritive]
1677
  rec_path=evt._data['value']['image']['path']
1678
  index="Style Recommendation Picture "+str(evt.index)
1679
  print("rec_path",rec_path)
1680
- prompt=recommendation_prompt[persona].format(language=language,length=length)
1681
- if new_crop:
1682
- image_paths=[new_crop,rec_path]
1683
- else:
1684
- image_paths=[image_path,rec_path]
1685
  result=get_gpt_response(openai_api_key, image_paths, prompt)
1686
  print("recommend result",result)
1687
  state += [(None, f"{result}")]
@@ -2034,7 +2051,8 @@ def create_ui():
2034
  multiselect=True,
2035
  label="Score", info="Please sort the pictures according to your preference"
2036
  )
2037
- with gr.Column(scale=3):
 
2038
  gallery_result = gr.Gallery(
2039
  label="Recommendations Based on Item",
2040
  height="auto",
@@ -2049,7 +2067,7 @@ def create_ui():
2049
  # show_share_button=True,
2050
  # show_download_button=True
2051
  )
2052
- with gr.Column(scale=3):
2053
  style_gallery_result = gr.Gallery(
2054
  label="Recommendations Based on Style",
2055
  height="auto",
@@ -2255,7 +2273,7 @@ def create_ui():
2255
 
2256
  gallery_result.select(
2257
  item_associate,
2258
- inputs=[image_path,new_crop_save_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state],
2259
  outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score],
2260
 
2261
 
@@ -2263,7 +2281,7 @@ def create_ui():
2263
 
2264
  style_gallery_result.select(
2265
  style_associate,
2266
- inputs=[image_path,new_crop_save_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state],
2267
  outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score],
2268
 
2269
 
 
692
  ]
693
 
694
  recommendation_prompt=[
695
+
696
+ [
697
+ '''I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:Recommendation reason: {{Recommendation based on objects in the image}}
698
  Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1.Each bullet point should be in {language} language, with a response length of about {length} words.''',
699
  '''
700
  When generating the answer, you should tell others that you are the creators of the first paintings and generate the text in the tone and manner as if you are the creator of the painting.
701
  I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:
702
+ Recommendation reason: {{ As the author of the first painting, I recommend based on the object I painted}} .
703
  Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1. Please generate the above points in the tone and manner as if you are the creator of this painting and start every sentence with I.
704
  Each bullet point should be in {language} language, with a response length of about {length} words.
705
  ''',
706
  '''
707
  When generating answers, you should tell people that you are the object itself that was selected in the first painting, and generate text in the tone and manner in which you are the object
708
  I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:
709
+ Recommendation reason: {{ As an object in the first painting, I am recommending based on myself}}.
710
  Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1. Please generate the above points in the tone and manner as if you are the object of this painting and start every sentence with I.
711
  Each bullet point should be in {language} language, with a response length of about {length} words.
712
+ '''],
713
+
714
+ [
715
+ '''I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:Recommendation reason: {{ Recommendation based on overall visual similarity}}
716
+ Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1.Each bullet point should be in {language} language, with a response length of about {length} words.''',
717
+ '''
718
+ When generating the answer, you should tell others that you are the creators of the first paintings and generate the text in the tone and manner as if you are the creator of the painting.
719
+ I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:
720
+ Recommendation reason: {{ As the author of the first painting, I recommend based on the overall similarity in appearance}}
721
+ Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1. Please generate the above points in the tone and manner as if you are the creator of this painting and start every sentence with I.
722
+ Each bullet point should be in {language} language, with a response length of about {length} words.
723
+ ''',
724
  '''
725
+ When generating answers, you should tell people that you are the object itself that was selected in the first painting, and generate text in the tone and manner in which you are the object
726
+ I want you to write the recommendation reason according to the following content, as a markdown outline with appropriate emojis that describe what you see according to the image:
727
+ Recommendation reason: {{As an object in the first painting, I am recommending based on the overall similarity of the first painting's appearance}}
728
+ Detailed analysis: Based on the recommendation reason, explain why you recommend image 2 after viewing image 1. Please generate the above points in the tone and manner as if you are the object of this painting and start every sentence with I.
729
+ Each bullet point should be in {language} language, with a response length of about {length} words.
730
+ '''],
731
+
732
 
733
 
734
 
735
+ ]
736
 
737
  gpt_state = 0
738
  VOICE = "en-GB-SoniaNeural"
 
1668
  return None
1669
 
1670
  # give the reason of recommendation
1671
+ async def item_associate(new_crop,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,evt: gr.SelectData):
1672
  persona=naritive_mapping[narritive]
1673
  rec_path=evt._data['value']['image']['path']
1674
+ index="Item Recommendation Picture "+ str(evt.index)
1675
  print("rec_path",rec_path)
1676
+ prompt=recommendation_prompt[0][persona].format(language=language,length=length)
1677
+
1678
+ image_paths=[new_crop,rec_path]
1679
+
 
1680
  result=get_gpt_response(openai_api_key, image_paths, prompt)
1681
  print("recommend result",result)
1682
  state += [(None, f"{result}")]
 
1692
  return state,state,audio_output,log_state,index,gr.update(value=[])
1693
 
1694
 
1695
+ async def style_associate(image_path,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,evt: gr.SelectData):
1696
  persona=naritive_mapping[narritive]
1697
  rec_path=evt._data['value']['image']['path']
1698
  index="Style Recommendation Picture "+str(evt.index)
1699
  print("rec_path",rec_path)
1700
+ prompt=recommendation_prompt[1][persona].format(language=language,length=length)
1701
+ image_paths=[image_path,rec_path]
 
 
 
1702
  result=get_gpt_response(openai_api_key, image_paths, prompt)
1703
  print("recommend result",result)
1704
  state += [(None, f"{result}")]
 
2051
  multiselect=True,
2052
  label="Score", info="Please sort the pictures according to your preference"
2053
  )
2054
+ with gr.Row():
2055
+
2056
  gallery_result = gr.Gallery(
2057
  label="Recommendations Based on Item",
2058
  height="auto",
 
2067
  # show_share_button=True,
2068
  # show_download_button=True
2069
  )
2070
+
2071
  style_gallery_result = gr.Gallery(
2072
  label="Recommendations Based on Style",
2073
  height="auto",
 
2273
 
2274
  gallery_result.select(
2275
  item_associate,
2276
+ inputs=[new_crop_save_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state],
2277
  outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score],
2278
 
2279
 
 
2281
 
2282
  style_gallery_result.select(
2283
  style_associate,
2284
+ inputs=[image_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state],
2285
  outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score],
2286
 
2287