Spaces:
Sleeping
Sleeping
Niki Zhang
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1721,18 +1721,12 @@ async def texttospeech(text, language,gender='female'):
|
|
| 1721 |
print(f"Error in texttospeech: {e}")
|
| 1722 |
return None
|
| 1723 |
|
| 1724 |
-
|
| 1725 |
-
|
| 1726 |
-
|
| 1727 |
-
if recommend_type=="Reasons":
|
| 1728 |
persona=naritive_mapping[narritive]
|
| 1729 |
-
index="Item Recommendation Picture "+ str(evt.index)
|
| 1730 |
-
print("rec_path",rec_path)
|
| 1731 |
-
|
| 1732 |
prompt=recommendation_prompt[0][persona].format(language=language,length=length)
|
| 1733 |
-
|
| 1734 |
-
image_paths=[new_crop,rec_path]
|
| 1735 |
-
|
| 1736 |
result=get_gpt_response(openai_api_key, image_paths, prompt)
|
| 1737 |
print("recommend result",result)
|
| 1738 |
state += [(None, f"{result}")]
|
|
@@ -1746,22 +1740,15 @@ async def item_associate(new_crop,openai_api_key,language,autoplay,length,log_st
|
|
| 1746 |
audio_output=None
|
| 1747 |
if autoplay:
|
| 1748 |
audio_output = await texttospeech(read_info, language)
|
| 1749 |
-
return state,state,audio_output,log_state,index,gr.update(value=[])
|
| 1750 |
-
|
| 1751 |
-
|
| 1752 |
-
|
| 1753 |
-
async def style_associate(image_path,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,artist,recommend_type,evt: gr.SelectData):
|
| 1754 |
-
rec_path=evt._data['value']['image']['path']
|
| 1755 |
-
if recommend_type=="Reasons":
|
| 1756 |
persona=naritive_mapping[narritive]
|
| 1757 |
|
| 1758 |
-
index="Style Recommendation Picture "+str(evt.index)
|
| 1759 |
-
print("rec_path",rec_path)
|
| 1760 |
if persona==1:
|
| 1761 |
prompt=recommendation_prompt[1][persona].format(language=language,length=length,artist=artist[8:])
|
| 1762 |
else:
|
| 1763 |
prompt=recommendation_prompt[1][persona].format(language=language,length=length)
|
| 1764 |
-
image_paths=[image_path,
|
| 1765 |
result=get_gpt_response(openai_api_key, image_paths, prompt )
|
| 1766 |
print("recommend result",result)
|
| 1767 |
state += [(None, f"{result}")]
|
|
@@ -1775,8 +1762,18 @@ async def style_associate(image_path,openai_api_key,language,autoplay,length,log
|
|
| 1775 |
audio_output=None
|
| 1776 |
if autoplay:
|
| 1777 |
audio_output = await texttospeech(read_info, language)
|
| 1778 |
-
return state,state,audio_output,log_state,index,gr.update(value=[])
|
| 1779 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1780 |
|
| 1781 |
|
| 1782 |
def change_naritive(session_type,image_input, state, click_state, paragraph, origin_image,narritive,task_instruct,gallery_output,style_gallery_result,reco_reasons,language="English"):
|
|
@@ -1920,6 +1917,10 @@ def create_ui():
|
|
| 1920 |
image_path=gr.State('')
|
| 1921 |
pic_index=gr.State(None)
|
| 1922 |
recomended_state=gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
|
@@ -2060,7 +2061,7 @@ def create_ui():
|
|
| 2060 |
# cap_everything_button = gr.Button(value="Caption Everything in a Paragraph", interactive=True)
|
| 2061 |
with gr.Column(visible=False) as modules_not_need_gpt2:
|
| 2062 |
with gr.Blocks():
|
| 2063 |
-
chatbot = gr.Chatbot(label="Chatbox", elem_classes="chatbot",likeable=True,height=
|
| 2064 |
with gr.Column() as modules_need_gpt3:
|
| 2065 |
chat_input = gr.MultimodalTextbox(interactive=True, file_types=[".txt"], placeholder="Message EyeSee...", show_label=False)
|
| 2066 |
with gr.Row():
|
|
@@ -2346,20 +2347,25 @@ def create_ui():
|
|
| 2346 |
|
| 2347 |
gallery_result.select(
|
| 2348 |
item_associate,
|
| 2349 |
-
inputs=[new_crop_save_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state
|
| 2350 |
-
outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score,selected_image],
|
| 2351 |
|
| 2352 |
|
| 2353 |
)
|
| 2354 |
|
| 2355 |
style_gallery_result.select(
|
| 2356 |
style_associate,
|
| 2357 |
-
inputs=[image_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state,artist_label
|
| 2358 |
-
outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score,selected_image],
|
| 2359 |
|
| 2360 |
|
| 2361 |
)
|
| 2362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2363 |
###############################################################################
|
| 2364 |
############# above part is for text to image #############
|
| 2365 |
###############################################################################
|
|
@@ -2701,10 +2707,7 @@ def create_ui():
|
|
| 2701 |
print("reason")
|
| 2702 |
|
| 2703 |
|
| 2704 |
-
|
| 2705 |
-
print_reason,
|
| 2706 |
-
inputs=[],
|
| 2707 |
-
outputs=[])
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
|
|
|
| 1721 |
print(f"Error in texttospeech: {e}")
|
| 1722 |
return None
|
| 1723 |
|
| 1724 |
+
async def get_recommendation(new_crop,image_path,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,recommend_type,artist,recomended_path):
|
| 1725 |
+
|
| 1726 |
+
if recommend_type=="Item":
|
|
|
|
| 1727 |
persona=naritive_mapping[narritive]
|
|
|
|
|
|
|
|
|
|
| 1728 |
prompt=recommendation_prompt[0][persona].format(language=language,length=length)
|
| 1729 |
+
image_paths=[new_crop,recomended_path]
|
|
|
|
|
|
|
| 1730 |
result=get_gpt_response(openai_api_key, image_paths, prompt)
|
| 1731 |
print("recommend result",result)
|
| 1732 |
state += [(None, f"{result}")]
|
|
|
|
| 1740 |
audio_output=None
|
| 1741 |
if autoplay:
|
| 1742 |
audio_output = await texttospeech(read_info, language)
|
| 1743 |
+
return state,state,audio_output,log_state,index,gr.update(value=[])
|
| 1744 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1745 |
persona=naritive_mapping[narritive]
|
| 1746 |
|
|
|
|
|
|
|
| 1747 |
if persona==1:
|
| 1748 |
prompt=recommendation_prompt[1][persona].format(language=language,length=length,artist=artist[8:])
|
| 1749 |
else:
|
| 1750 |
prompt=recommendation_prompt[1][persona].format(language=language,length=length)
|
| 1751 |
+
image_paths=[image_path,recomended_path]
|
| 1752 |
result=get_gpt_response(openai_api_key, image_paths, prompt )
|
| 1753 |
print("recommend result",result)
|
| 1754 |
state += [(None, f"{result}")]
|
|
|
|
| 1762 |
audio_output=None
|
| 1763 |
if autoplay:
|
| 1764 |
audio_output = await texttospeech(read_info, language)
|
| 1765 |
+
return state,state,audio_output,log_state,index,gr.update(value=[])
|
| 1766 |
+
|
| 1767 |
+
|
| 1768 |
+
# give the reason of recommendation
|
| 1769 |
+
async def item_associate(new_crop,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,evt: gr.SelectData):
|
| 1770 |
+
rec_path=evt._data['value']['image']['path']
|
| 1771 |
+
return state,state,None,log_state,None,gr.update(value=[]),rec_path,rec_path,"Item"
|
| 1772 |
+
|
| 1773 |
+
|
| 1774 |
+
async def style_associate(image_path,openai_api_key,language,autoplay,length,log_state,sort_score,narritive,state,artist,evt: gr.SelectData):
|
| 1775 |
+
rec_path=evt._data['value']['image']['path']
|
| 1776 |
+
return state,state,None,log_state,None,gr.update(value=[]),rec_path, rec_path,"Style"
|
| 1777 |
|
| 1778 |
|
| 1779 |
def change_naritive(session_type,image_input, state, click_state, paragraph, origin_image,narritive,task_instruct,gallery_output,style_gallery_result,reco_reasons,language="English"):
|
|
|
|
| 1917 |
image_path=gr.State('')
|
| 1918 |
pic_index=gr.State(None)
|
| 1919 |
recomended_state=gr.State([])
|
| 1920 |
+
|
| 1921 |
+
recomended_path=gr.State(None)
|
| 1922 |
+
recomended_type=gr.State(None)
|
| 1923 |
+
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
|
|
|
| 2061 |
# cap_everything_button = gr.Button(value="Caption Everything in a Paragraph", interactive=True)
|
| 2062 |
with gr.Column(visible=False) as modules_not_need_gpt2:
|
| 2063 |
with gr.Blocks():
|
| 2064 |
+
chatbot = gr.Chatbot(label="Chatbox", elem_classes="chatbot",likeable=True,height=700,bubble_full_width=False)
|
| 2065 |
with gr.Column() as modules_need_gpt3:
|
| 2066 |
chat_input = gr.MultimodalTextbox(interactive=True, file_types=[".txt"], placeholder="Message EyeSee...", show_label=False)
|
| 2067 |
with gr.Row():
|
|
|
|
| 2347 |
|
| 2348 |
gallery_result.select(
|
| 2349 |
item_associate,
|
| 2350 |
+
inputs=[new_crop_save_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state],
|
| 2351 |
+
outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score,selected_image,recomended_path, recomended_type],
|
| 2352 |
|
| 2353 |
|
| 2354 |
)
|
| 2355 |
|
| 2356 |
style_gallery_result.select(
|
| 2357 |
style_associate,
|
| 2358 |
+
inputs=[image_path,openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state,artist_label],
|
| 2359 |
+
outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score,selected_image,recomended_path,recomended_type],
|
| 2360 |
|
| 2361 |
|
| 2362 |
)
|
| 2363 |
|
| 2364 |
+
selected_image.select(
|
| 2365 |
+
get_recommendation,
|
| 2366 |
+
inputs=[new_crop_save_path,image_path, openai_api_key,language,auto_play,length,log_state,sort_rec,naritive,recomended_state,recomended_type,artist_label,recomended_path],
|
| 2367 |
+
outputs=[recommend_bot,recomended_state,output_audio,log_state,pic_index,recommend_score])
|
| 2368 |
+
|
| 2369 |
###############################################################################
|
| 2370 |
############# above part is for text to image #############
|
| 2371 |
###############################################################################
|
|
|
|
| 2707 |
print("reason")
|
| 2708 |
|
| 2709 |
|
| 2710 |
+
|
|
|
|
|
|
|
|
|
|
| 2711 |
|
| 2712 |
|
| 2713 |
|