From dd351d3dca0af62e245577c0580eca6435e8c945 Mon Sep 17 00:00:00 2001 From: Dahai Peng Date: Mon, 19 Aug 2024 17:24:13 +0800 Subject: [PATCH] add upload file feature --- apps/datascience_assistant/app.py | 68 ++++++++++++++++++------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/apps/datascience_assistant/app.py b/apps/datascience_assistant/app.py index d410c904..db3dcbf8 100644 --- a/apps/datascience_assistant/app.py +++ b/apps/datascience_assistant/app.py @@ -2,34 +2,44 @@ import sys import streamlit as st -from modelscope_agent.agents.data_science_assistant import DataScienceAssistant -from modelscope_agent.tools.metagpt_tools.tool_recommend import \ - TypeMatchToolRecommender -current_dir = os.path.dirname(os.path.abspath(__file__)) -project_root_path = os.path.abspath(os.path.join(current_dir, '../../')) -sys.path.append(project_root_path) -llm_config = { - 'model': 'qwen2-72b-instruct', - 'model_server': 'dashscope', -} -os.environ['DASHSCOPE_API_KEY'] = input( - 'Please input your dashscope api key: ') -data_science_assistant = DataScienceAssistant( - llm=llm_config, tool_recommender=TypeMatchToolRecommender(tools=[''])) -st.title('Data Science Assistant') -st.write( - 'This is a data science assistant that can help you with your data science tasks.' -) -st.write( - 'Please input your request and upload files then click the submit button.') +os.environ['DASHSCOPE_API_KEY'] = 'YOUR_API_KEY' -files = st.file_uploader( - 'Please upload files that you need. ', accept_multiple_files=True) -last_file_name = '' -user_request = st.text_area('User Request') -if st.button('submit'): - for file in files: - with open(file.name, 'wb') as f: - f.write(file.getbuffer()) - data_science_assistant.run(user_request=user_request, streamlit=True) + +def setup_project_paths(): + current_dir = os.path.dirname(os.path.abspath(__file__)) # noqa + project_root_path = os.path.abspath(os.path.join(current_dir, + '../../')) # noqa + sys.path.append(project_root_path) # noqa + + +if __name__ == '__main__': + setup_project_paths() + from modelscope_agent.agents.data_science_assistant import \ + DataScienceAssistant # noqa + from modelscope_agent.tools.metagpt_tools.tool_recommend import \ + TypeMatchToolRecommender # noqa + st.title('Data Science Assistant') + st.write( + 'This is a data science assistant that can help you with your data science tasks.' + ) + st.write( + 'Please input your request and upload files then click the submit button.' + ) + + files = st.file_uploader( + 'Please upload files that you need. ', accept_multiple_files=True) + last_file_name = '' + user_request = st.text_area('User Request') + if st.button('submit'): + llm_config = { + 'model': 'qwen2-72b-instruct', + 'model_server': 'dashscope', + } + data_science_assistant = DataScienceAssistant( + llm=llm_config, + tool_recommender=TypeMatchToolRecommender(tools=[''])) + for file in files: + with open(file.name, 'wb') as f: + f.write(file.getbuffer()) + data_science_assistant.run(user_request=user_request, streamlit=True)