code: import os
  import time
  import pickle as pkl
  # import re
  # import yaml
  import toml
  import logging
  from datetime import date
  
  # import aiohttp
  import pandas as pd
  from pytrends.request import TrendReq
  import serpapi
  from serpapi import GoogleSearch
  import asyncio
  import streamlit as st
  import streamlit.components.v1 as components
  import streamlit_authenticator as stauth
  import langchain
  # from langchain.utilities import GoogleSerperAPIWrapper
  from langchain.text_splitter import RecursiveCharacterTextSplitter
  from langchain.chat_models import ChatOpenAI
  from langchain.agents import initialize_agent, Tool, AgentType
  from langchain.docstore.document import Document
  from langchain.chains.qa_with_sources import load_qa_with_sources_chain
  from langchain.llms import OpenAI
  from langchain.prompts.prompt import PromptTemplate
  import openai
  
  from dotenv import load_dotenv
  load_dotenv()
  
  
  ########### ===== config ===== #############
  config_path = '.streamlit/secrets.toml'
  # print(f" os.listdir('.') -> { os.listdir('.')}")
  
  if os.path.exists(config_path):
  	logging.info(f"{config_path} exists")
  	config = toml.load(open( config_path, 'r'))
  else:
  	logging.info( f"secrets -> {st.secrets}" )
  	config = dict(st.secrets.items())
  print( f"config -> {config}")
  for k in ['name', 'authentication_status', 'username' ]:
  	st.session_state[k] = None
  logging.info(f"session state -> {st.session_state}")
  openai.api_key = os.environ.get("OPENAI_API_KEY") or config["settings"]["OPENAI_API_KEY"]
  os.environ["OPENAI_API_KEY"] = openai.api_key
  
  secret_key = os.environ.get('SERP_APIKEY') or config["settings"]["SERP_APIKEY"]
  logging.info(f"serp api key -> {secret_key}")
  # serp_client = serpapi.Client(api_key=secret_key)
  pytrends = TrendReq(hl='zh-TW', tz=480, timeout=(10,25), retries=2, backoff_factor=0.1, requests_args={'verify':False})
  
  ########### ==================== #############
  
  
  ### ===== Creating a login widget ===== ###
  authenticator = stauth.Authenticate(
  		config['credentials'],
  		config['cookie']['name'],
  		config['cookie']['key'],
  		config['cookie']['expiry_days'],
  		config['preauthorized']
  )
  name, authentication_status, username = authenticator.login('Login', 'main')
  is_production = os.environ.get("PRODUCTION") or config["settings"]["PRODUCTION"]
  logging.info(f"is_production -> {is_production}")
  ########### ==================== #############
  
  
  @st.cache_data
  def get_trending_searches(today) -> pd.DataFrame:
      """
      Get trending searches from Google Trends
      """
      results = pytrends.trending_searches(pn='taiwan')
      return results
  
  @st.cache_data
  def get_search_results( secret_key, query: str, today: str) -> dict:
      """
      Get search results from serpapi.com
      """
      print(f"secret_key -> {secret_key[-4:]}, query -> {query}, today -> {today}")
      serp_client=serpapi.Client(api_key=secret_key)
      results = serp_client.search({
          'engine': 'google',
          'q': query,
      })
      return results.as_dict()
  
  
  audio_input_dir = "data/audio"
  audio_output_dir = "data/audio"
  transcript_input_dir = "data/transcripts"
  transcript_output_dir = "data/transcripts"
  summary_input_dir = "data/summary"
  summary_output_dir = "data/summary"
  
  ### === load model & utilities === ###
  from model import get_answer, aget_answer
  from postprocess import parse_url, parse_element
  from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary	
  
  ### ===== Authenticating users ===== ###
  if authentication_status:
  	col1, col2, col3 , col4, col5, col6, col7 = st.columns(7)
  	with col4:
  		# st.write(f'Welcome *{name}*')
  		st.write(f'Welcome!')
  		# st.write(f'*{name}*')
  		# st.markdown(f"<p style='text-align: center;'> {name} </p>", unsafe_allow_html=True)
  		authenticator.logout('Logout', 'main')
  	# st.write(f'\n\n\n\n')
  
  	st.title("生產力小幫手")
  	# st.divider() 
  
  
  	tab1, tab2, tab3, tab4, tab5, tab6, tab7 = st.tabs(["疼痛小幫手", "切割錄音檔", "錄音轉文字", "文字改寫", "總結摘要", "錄音檔摘要", "火熱話題"])
  
  	with tab1:
  		question = st.text_input("病患描述問題", placeholder="肩膀不太舒服，前幾天有去打球，會不會是韌帶拉傷？")
  
  		if question:
  			if is_production:
  				res = get_answer(question)
  			else:
  				res = asyncio.run(aget_answer(question))
  
  			urls = res['urls']
  
  			st.write("【建議回覆】")
  			st.write(res["output_text"])
  			
  
  			print( f"found urls -> {urls}" )
  			html = ""
  			if len(urls)>0:
  				for url in urls:
  					html += f"""<br><a href=\"{url}\" style="color:gray">開啟網頁：{url}</a>"""
  			html = f"<div>{html}</div>"
  			components.html( html, height=600, scrolling=True)
  
  	with tab2: 
  		## --- upload file --- ##
  		with st.form("upload-audio-form", clear_on_submit=True):
  			uploaded_file = st.file_uploader("Upload an audio clip", key='split_audio', type=["wav", "mp3", "m4a"])
  			submitted = st.form_submit_button("UPLOAD")
  			if submitted and uploaded_file:
  				## -- read file -- ##
  				sound_bytes = uploaded_file.getvalue() # bytes
  				
  				file_obj = compose_file_path( uploaded_file.name, output_prefix = None, output_dir = audio_input_dir, output_ext = None)
  				audio_file_path = file_obj['output_file_path']
  				print( f"audio_file_path: { audio_file_path}")
  				with open( audio_file_path, "wb") as f:
  					f.write(sound_bytes)
  
  				## --- split --- ##
  				with st.spinner(f"reading from { audio_file_path}"):
  					multi_file_paths = split( in_file_path = audio_file_path, length = 10)
  
  	with tab3: 
  		## --- upload file --- ##
  		transcript_file_path = ""
  		transcripted = 0
  		with st.form("upload-audio-clip-form", clear_on_submit=True):
  			uploaded_file = st.file_uploader("Upload an audio clip", key = 'transcribe_audio', type=["wav", "mp3", "m4a"])
  			submitted = st.form_submit_button("UPLOAD")
  			if submitted and uploaded_file:
  				## -- read file -- ##
  				sound_bytes = uploaded_file.getvalue() # bytes
  				file_obj = compose_file_path( input_file_path=uploaded_file.name, output_prefix = None, output_dir = audio_input_dir, output_ext = None)
  				audio_file_path = file_obj['output_file_path']
  				print( f"audio_file_path: { audio_file_path}")
  				with open( audio_file_path, "wb") as f:
  					f.write(sound_bytes)
  
  				## --- transcribe --- ##		
  				start_time = time.time()
  				st.divider()	
  				file_obj = compose_file_path( audio_file_path, output_prefix = None, output_dir = transcript_input_dir, output_ext = "txt")
  				transcript_file_path = file_obj['output_file_path']
  				if os.path.exists(transcript_file_path): 
  					print(f"{transcript_file_path} already exists. will skip this file.")	 
  				with st.spinner(f"written transcript to { transcript_file_path}"):
  					transcript = sound2txt( audio_file_path, transcript_file_path)
  					st.write(transcript['text'])
  				print( f"Elapsed time: {time.time() - start_time} seconds")
  			transcripted = 1
  		if transcripted and os.path.exists(transcript_file_path):
  			with open(transcript_file_path) as f:
  				st.download_button('下載逐字稿', f, file_name = os.path.basename(transcript_file_path), )  # Defaults to 'text/plain'
  
  	with tab4:
  		
  		rewrite_chain = get_rewrite_chain()
  		rewrite_file_path = ""
  		rewritten = 0
  		question = st.text_input(
  				"你希望整理會議逐字稿的方式（用簡短的英文描述）",
  				"correct typos, remove redundant sentences/words and add punctuations",
  				placeholder="correct typos, remove redundant sentences/words and add punctuations",
  				# disabled=not uploaded_file,
  			)
  		
  		with st.form("upload-transcript-clip-form", clear_on_submit=True):
  			rewrite_uploaded_file = st.file_uploader("Upload a transcript or a document (txt file)", type="txt")
  			submitted = st.form_submit_button("UPLOAD")
  			
  			if submitted and rewrite_uploaded_file and question and not openai.api_key:
  				st.info("Please add your OPENAI API KEY to environment to continue.")
  				
  			if submitted and rewrite_uploaded_file and question and openai.api_key:
  				## -- read file -- ##
  				article = rewrite_uploaded_file.read().decode()
  				
  				file_obj = compose_file_path( 
  					input_file_path = rewrite_uploaded_file.name, output_prefix = "rewrite", output_dir = transcript_output_dir, output_ext = "txt"
  				)
  				rewrite_file_path = file_obj['output_file_path']
  				# assert not os.path.exists( transcript_file_path), f"File { transcript_file_path} already exists."
  
  				## -- split into chunks -- ##
  				text_splitter = RecursiveCharacterTextSplitter(
  					chunk_size=1024,
  					chunk_overlap=20,
  				)
  				paragraphs = text_splitter.split_text(article)
  
  				## --- anthropic --- ##
  				# prompt = f"""
  				# {anthropic.HUMAN_PROMPT} Here's an article:\n\n<article>
  				# {article}\n\n</article>\n\n{question}{anthropic.AI_PROMPT}
  				# """
  				# client = anthropic.Client(anthropic_api_key)
  				# #client = anthropic.Client(st.secrets.anthropic_api_key)
  				# response = client.completion(
  				#     prompt=prompt,
  				#     stop_sequences=[anthropic.HUMAN_PROMPT],
  				#     model="claude-v1",
  				#     max_tokens_to_sample=100,
  				# )
  				# st.write("### Answer")
  				# st.write(response["completion"])
  
  				## --- openai --- ##
  				
  				st.write("### Rewritten transcript")
  				with st.spinner(f"written to { rewrite_file_path}"):
  					for paragraph in paragraphs: 
  						try:
  							res = rewrite_chain({"functions": question, "paragraph": paragraph}, return_only_outputs = True)
  						except Exception as e:
  							print(e)
  							continue
  						st.write(res["text"])
  						st.write("---")
  						with open( rewrite_file_path, "a") as f:
  							f.write(res["text"])
  						# rewrite_file_paths.append( rewrite_file_path)
  			rewritten = 1
  
  		if rewritten and os.path.exists(rewrite_file_path):
  			with open(rewrite_file_path) as f:
  				st.download_button('下載加入標點符號後的逐字稿', f, file_name = os.path.basename(rewrite_file_path),  key = f"download-button-{rewrite_file_path}")  # Defaults to 'text/plain'
  
  	with tab5: 
  		instruction = st.text_input(
  				"你希望總結會議逐字稿的方式（用簡短的英文描述）",
  				"give helpful and concise summary with action items in traditional chinese.",
  				placeholder="give helpful and concise summary with action items in traditional chinese.",
  				# disabled=not summary_uploaded_file,
  			)
  
  		summarized = 0
  		summary_file_path = ""
  		with st.form("upload-summarize-clip-form", clear_on_submit=True):
  			summary_uploaded_file = st.file_uploader("Upload a transcript or a document (txt file)", type="txt")
  			summarize_submitted = st.form_submit_button("UPLOAD")
  			
  			if summarize_submitted and summary_uploaded_file and instruction and not openai.api_key:
  				st.info("Please add your OPENAI API KEY to environment to continue.")
  				
  			if summarize_submitted and summary_uploaded_file and instruction and openai.api_key:
  				## -- read file -- ##
  				article = summary_uploaded_file.read().decode()
  				
  				file_obj = compose_file_path( 
  					input_file_path = summary_uploaded_file.name, output_prefix = "summary", output_dir = summary_output_dir, output_ext = "txt"
  				)
  				summary_file_path = file_obj['output_file_path']
  
  				## -- split into chunks -- ##
  				text_splitter = RecursiveCharacterTextSplitter(
  					chunk_size=1024,
  					chunk_overlap=100,
  				)
  				paragraphs = text_splitter.split_text(article)
  
  				## -- summarize -- ##
  				st.write("### Summarize transcript")
  				with st.spinner(f"written to { summary_file_path}"):
  					summarize_chain = get_summarize_chain()
  					with open( summary_file_path, "w") as f:
  						for paragraph in paragraphs: 
  							try:
  								res = summarize_chain( {"input_documents": [ Document( page_content=paragraph) ], "functions": instruction} )
  								summary = res['output_text']
  							except Exception as e:
  								print(e)
  								continue
  							st.write(summary)
  							st.write("---")
  							f.write(summary)
  			summarized = 1
  
  		if summarized and os.path.exists(summary_file_path):
  			with open(summary_file_path) as f:
  				st.download_button('下載摘要', f, file_name = os.path.basename(summary_file_path), key = f"download-button-{summary_file_path}")  # Defaults to 'text/plain'
  
  	with tab6: 
  		# summarize_chain = load_summarize_chain()
  		# data/audio/GMT20230613-051643_Recording.m4a_0.m4a
  		# with open("data/transcripts/GMT20230613-051643_Recording.m4a_0.txt") as f:
  		# 	transcript = f.read()
  		# st.markdown( f'<p style="background-color: rgba(100,100,200,.2);">{transcript}</p>', unsafe_allow_html=True)
  
  		## --- upload file --- ##
  		with st.form("end-to-end-upload-audio-form", clear_on_submit=True):
  			uploaded_file = st.file_uploader("Upload an audio clip", key='end_to_end', type=["wav", "mp3", "m4a"])
  			submitted = st.form_submit_button("UPLOAD")
  			if submitted and uploaded_file:
  				## -- read file -- ##
  				with st.spinner(f"uploaded { uploaded_file.name}"):
  					sound_bytes = uploaded_file.getvalue() # bytes
  					audio_file_path = compose_file_path( input_file_path = uploaded_file.name, output_prefix = None, output_dir = audio_input_dir, output_ext = None)['output_file_path']
  					print( f"audio_file_path: {audio_file_path}")
  					with open( audio_file_path, "wb") as f:
  						f.write(sound_bytes)
  					## --- split --- ##		
  					audio_file_paths = split( in_file_path = audio_file_path, length = 10)
  
  				## --- transcribe --- ##		
  				st.write("### Transcribing audio")
  				with st.spinner(f"transcribe { ', '.join(audio_file_paths) }"):
  					transcripts = []
  					transcript_file_paths = []
  					for i, audio_file_path in enumerate(audio_file_paths):
  						start_time = time.time()
  						
  						transcript_file_path = compose_file_path( input_file_path = audio_file_path, output_prefix = None, output_dir = transcript_input_dir, output_ext = "txt")['output_file_path']
  						transcript_file_paths.append(transcript_file_path)
  
  						st.write(f"Trascribing {i}-th clip out of total {len(audio_file_paths)} clips.")
  						transcript = sound2txt( audio_file_path, transcript_file_path)
  
  						st.write(transcript['text'][:50])
  						st.divider()
  						transcripts.append( transcript['text'])
  						print( f"[transcription] Elapsed time: {time.time() - start_time} seconds")
  					# print( f"Transcript: {transcript}")
  				
  				## --- Rewrite --- ##
  				st.write("### Rewritten transcript")
  				with st.spinner(f"rewritten { ','.join(transcript_file_paths)}"):
  					text_splitter = RecursiveCharacterTextSplitter(
  						chunk_size=1024,
  						chunk_overlap=20,
  					)
  					rewrite_instruction = "correct typos, remove redundant sentences/words and add punctuations"
  					rewrite_file_paths = []
  					rewrites = []
  					for i, blob in enumerate(zip(transcript_file_paths, transcripts)):
  						transcript_file_path, transcript = blob
  						paragraphs = text_splitter.split_text( "\n".join(transcript) )
  						rewrite_file_path = compose_file_path( input_file_path = transcript_file_path, output_prefix = "rewrite", output_dir = transcript_output_dir, output_ext = "txt")['output_file_path']
  						rewrite_file_paths.append(rewrite_file_path)
  						st.write(f"Rewriting {i}-th transcript out of total {len(transcript_file_paths)} transcripts.")
  						for paragraph in paragraphs: 
  							try:
  								res = rewrite_chain({"functions": rewrite_instruction, "paragraph": paragraph}, return_only_outputs = True)
  							except Exception as e:
  								print(e)
  								continue
  							with open( rewrite_file_path, "a") as f:
  								f.write(res["text"])
  							st.write(res["text"][:50])
  							st.divider()
  
  				## --- summarize --- ##
  				with st.spinner(f"summarize { ', '.join(rewrite_file_paths) }"):
  					summary_text = ""
  					for rewrite, rewrite_file_path in zip( rewrites, rewrite_file_paths):
  						start_time = time.time()
  						summary_file_path = compose_file_path( input_file_path = rewrite_file_path, output_prefix = "summary", output_dir = summary_output_dir, output_ext = "txt")['output_file_path']
  						summary = text2summary( rewrite, summary_file_path, instruction = "give helpful and concise summary with action items in traditional chinese.")
  						st.write(summary)
  						st.divider()
  						summary_text += f"{summary}\n"
  						print( f"[summary] Elapsed time: {time.time() - start_time} seconds")
  	with tab7:
  		if False:
  			# today = date.today()
  			# topn_results = 3
  			# topn_articles = 1
  			# trend_results = get_trending_searches(today)
  			# highlights = []
  			# for query in trend_results[0].values[:topn_results]:
  			# 	search_results = get_search_results( secret_key, query, str(today) )
  			# 	highlights += search_results['organic_results'][:topn_articles]
  			# highlights = pd.DataFrame(highlights)
  			params = {
  				"api_key": secret_key,
  				"engine": "google_trends_trending_now",
  				"frequency": "daily",
  				"geo": "TW",
  				"hl": "zh-tw"
  			}
  			search = GoogleSearch(params)
  			results = search.get_dict()
  			content = []
  			for ds in results['daily_searches']:
  				for s in ds['searches']:
  					q = s['query']
  					if 'articles' in s and len(s['articles'])>0:
  						link = s['articles'][0]['link']
  						title = s['articles'][0]['title']
  						snippet = s['articles'][0]['snippet']
  					else:
  						continue
  					content.append({'query': q, 'title': title, 'snippet': snippet, 'link': link})
  			st.dataframe(pd.DataFrame(content))
  		else:
  			st.write("Coming soon...")
  
  
  elif authentication_status == False:
  	st.error('Username/password is incorrect')
  	
  elif authentication_status == None:
  	st.warning('Please enter your username and password')
  
  
apis: langchain.text_splitter.RecursiveCharacterTextSplitter langchain.docstore.document.Document
extract_api: [((872, 885), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (883, 885), False, 'from dotenv import load_dotenv\n'), ((1028, 1055), 'os.path.exists', 'os.path.exists', (['config_path'], {}), '(config_path)\n', (1042, 1055), False, 'import os\n'), ((1341, 1393), 'logging.info', 'logging.info', (['f"""session state -> {st.session_state}"""'], {}), "(f'session state -> {st.session_state}')\n", (1353, 1393), False, 'import logging\n'), ((1611, 1656), 'logging.info', 'logging.info', (['f"""serp api key -> {secret_key}"""'], {}), "(f'serp api key -> {secret_key}')\n", (1623, 1656), False, 'import logging\n'), ((1719, 1834), 'pytrends.request.TrendReq', 'TrendReq', ([], {'hl': '"""zh-TW"""', 'tz': '(480)', 'timeout': '(10, 25)', 'retries': '(2)', 'backoff_factor': '(0.1)', 'requests_args': "{'verify': False}"}), "(hl='zh-TW', tz=480, timeout=(10, 25), retries=2, backoff_factor=\n    0.1, requests_args={'verify': False})\n", (1727, 1834), False, 'from pytrends.request import TrendReq\n'), ((1938, 2099), 'streamlit_authenticator.Authenticate', 'stauth.Authenticate', (["config['credentials']", "config['cookie']['name']", "config['cookie']['key']", "config['cookie']['expiry_days']", "config['preauthorized']"], {}), "(config['credentials'], config['cookie']['name'], config\n    ['cookie']['key'], config['cookie']['expiry_days'], config['preauthorized']\n    )\n", (1957, 2099), True, 'import streamlit_authenticator as stauth\n'), ((2260, 2309), 'logging.info', 'logging.info', (['f"""is_production -> {is_production}"""'], {}), "(f'is_production -> {is_production}')\n", (2272, 2309), False, 'import logging\n'), ((1058, 1095), 'logging.info', 'logging.info', (['f"""{config_path} exists"""'], {}), "(f'{config_path} exists')\n", (1070, 1095), False, 'import logging\n'), ((1148, 1188), 'logging.info', 'logging.info', (['f"""secrets -> {st.secrets}"""'], {}), "(f'secrets -> {st.secrets}')\n", (1160, 1188), False, 'import logging\n'), ((1411, 1443), 'os.environ.get', 'os.environ.get', (['"""OPENAI_API_KEY"""'], {}), "('OPENAI_API_KEY')\n", (1425, 1443), False, 'import os\n'), ((1544, 1573), 'os.environ.get', 'os.environ.get', (['"""SERP_APIKEY"""'], {}), "('SERP_APIKEY')\n", (1558, 1573), False, 'import os\n'), ((2195, 2223), 'os.environ.get', 'os.environ.get', (['"""PRODUCTION"""'], {}), "('PRODUCTION')\n", (2209, 2223), False, 'import os\n'), ((2797, 2831), 'serpapi.Client', 'serpapi.Client', ([], {'api_key': 'secret_key'}), '(api_key=secret_key)\n', (2811, 2831), False, 'import serpapi\n'), ((3525, 3538), 'streamlit.columns', 'st.columns', (['(7)'], {}), '(7)\n', (3535, 3538), True, 'import streamlit as st\n'), ((3791, 3809), 'streamlit.title', 'st.title', (['"""生產力小幫手"""'], {}), "('生產力小幫手')\n", (3799, 3809), True, 'import streamlit as st\n'), ((3873, 3942), 'streamlit.tabs', 'st.tabs', (["['疼痛小幫手', '切割錄音檔', '錄音轉文字', '文字改寫', '總結摘要', '錄音檔摘要', '火熱話題']"], {}), "(['疼痛小幫手', '切割錄音檔', '錄音轉文字', '文字改寫', '總結摘要', '錄音檔摘要', '火熱話題'])\n", (3880, 3942), True, 'import streamlit as st\n'), ((1206, 1224), 'streamlit.secrets.items', 'st.secrets.items', ([], {}), '()\n', (1222, 1224), True, 'import streamlit as st\n'), ((3587, 3608), 'streamlit.write', 'st.write', (['f"""Welcome!"""'], {}), "(f'Welcome!')\n", (3595, 3608), True, 'import streamlit as st\n'), ((3969, 4032), 'streamlit.text_input', 'st.text_input', (['"""病患描述問題"""'], {'placeholder': '"""肩膀不太舒服，前幾天有去打球，會不會是韌帶拉傷？"""'}), "('病患描述問題', placeholder='肩膀不太舒服，前幾天有去打球，會不會是韌帶拉傷？')\n", (3982, 4032), True, 'import streamlit as st\n'), ((6949, 6968), 'utils.get_rewrite_chain', 'get_rewrite_chain', ([], {}), '()\n', (6966, 6968), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((7023, 7232), 'streamlit.text_input', 'st.text_input', (['"""你希望整理會議逐字稿的方式（用簡短的英文描述）"""', '"""correct typos, remove redundant sentences/words and add punctuations"""'], {'placeholder': '"""correct typos, remove redundant sentences/words and add punctuations"""'}), "('你希望整理會議逐字稿的方式（用簡短的英文描述）',\n    'correct typos, remove redundant sentences/words and add punctuations',\n    placeholder=\n    'correct typos, remove redundant sentences/words and add punctuations')\n", (7036, 7232), True, 'import streamlit as st\n'), ((9715, 9942), 'streamlit.text_input', 'st.text_input', (['"""你希望總結會議逐字稿的方式（用簡短的英文描述）"""', '"""give helpful and concise summary with action items in traditional chinese."""'], {'placeholder': '"""give helpful and concise summary with action items in traditional chinese."""'}), "('你希望總結會議逐字稿的方式（用簡短的英文描述）',\n    'give helpful and concise summary with action items in traditional chinese.'\n    , placeholder=\n    'give helpful and concise summary with action items in traditional chinese.'\n    )\n", (9728, 9942), True, 'import streamlit as st\n'), ((17034, 17076), 'streamlit.error', 'st.error', (['"""Username/password is incorrect"""'], {}), "('Username/password is incorrect')\n", (17042, 17076), True, 'import streamlit as st\n'), ((4182, 4200), 'streamlit.write', 'st.write', (['"""【建議回覆】"""'], {}), "('【建議回覆】')\n", (4190, 4200), True, 'import streamlit as st\n'), ((4204, 4232), 'streamlit.write', 'st.write', (["res['output_text']"], {}), "(res['output_text'])\n", (4212, 4232), True, 'import streamlit as st\n'), ((4437, 4486), 'streamlit.components.v1.html', 'components.html', (['html'], {'height': '(600)', 'scrolling': '(True)'}), '(html, height=600, scrolling=True)\n', (4452, 4486), True, 'import streamlit.components.v1 as components\n'), ((4537, 4587), 'streamlit.form', 'st.form', (['"""upload-audio-form"""'], {'clear_on_submit': '(True)'}), "('upload-audio-form', clear_on_submit=True)\n", (4544, 4587), True, 'import streamlit as st\n'), ((4608, 4699), 'streamlit.file_uploader', 'st.file_uploader', (['"""Upload an audio clip"""'], {'key': '"""split_audio"""', 'type': "['wav', 'mp3', 'm4a']"}), "('Upload an audio clip', key='split_audio', type=['wav',\n    'mp3', 'm4a'])\n", (4624, 4699), True, 'import streamlit as st\n'), ((4711, 4742), 'streamlit.form_submit_button', 'st.form_submit_button', (['"""UPLOAD"""'], {}), "('UPLOAD')\n", (4732, 4742), True, 'import streamlit as st\n'), ((5411, 5466), 'streamlit.form', 'st.form', (['"""upload-audio-clip-form"""'], {'clear_on_submit': '(True)'}), "('upload-audio-clip-form', clear_on_submit=True)\n", (5418, 5466), True, 'import streamlit as st\n'), ((5487, 5584), 'streamlit.file_uploader', 'st.file_uploader', (['"""Upload an audio clip"""'], {'key': '"""transcribe_audio"""', 'type': "['wav', 'mp3', 'm4a']"}), "('Upload an audio clip', key='transcribe_audio', type=[\n    'wav', 'mp3', 'm4a'])\n", (5503, 5584), True, 'import streamlit as st\n'), ((5597, 5628), 'streamlit.form_submit_button', 'st.form_submit_button', (['"""UPLOAD"""'], {}), "('UPLOAD')\n", (5618, 5628), True, 'import streamlit as st\n'), ((6719, 6755), 'os.path.exists', 'os.path.exists', (['transcript_file_path'], {}), '(transcript_file_path)\n', (6733, 6755), False, 'import os\n'), ((7282, 7342), 'streamlit.form', 'st.form', (['"""upload-transcript-clip-form"""'], {'clear_on_submit': '(True)'}), "('upload-transcript-clip-form', clear_on_submit=True)\n", (7289, 7342), True, 'import streamlit as st\n'), ((7371, 7447), 'streamlit.file_uploader', 'st.file_uploader', (['"""Upload a transcript or a document (txt file)"""'], {'type': '"""txt"""'}), "('Upload a transcript or a document (txt file)', type='txt')\n", (7387, 7447), True, 'import streamlit as st\n'), ((7463, 7494), 'streamlit.form_submit_button', 'st.form_submit_button', (['"""UPLOAD"""'], {}), "('UPLOAD')\n", (7484, 7494), True, 'import streamlit as st\n'), ((9445, 9478), 'os.path.exists', 'os.path.exists', (['rewrite_file_path'], {}), '(rewrite_file_path)\n', (9459, 9478), False, 'import os\n'), ((10034, 10093), 'streamlit.form', 'st.form', (['"""upload-summarize-clip-form"""'], {'clear_on_submit': '(True)'}), "('upload-summarize-clip-form', clear_on_submit=True)\n", (10041, 10093), True, 'import streamlit as st\n'), ((10122, 10198), 'streamlit.file_uploader', 'st.file_uploader', (['"""Upload a transcript or a document (txt file)"""'], {'type': '"""txt"""'}), "('Upload a transcript or a document (txt file)', type='txt')\n", (10138, 10198), True, 'import streamlit as st\n'), ((10224, 10255), 'streamlit.form_submit_button', 'st.form_submit_button', (['"""UPLOAD"""'], {}), "('UPLOAD')\n", (10245, 10255), True, 'import streamlit as st\n'), ((11610, 11643), 'os.path.exists', 'os.path.exists', (['summary_file_path'], {}), '(summary_file_path)\n', (11624, 11643), False, 'import os\n'), ((12208, 12269), 'streamlit.form', 'st.form', (['"""end-to-end-upload-audio-form"""'], {'clear_on_submit': '(True)'}), "('end-to-end-upload-audio-form', clear_on_submit=True)\n", (12215, 12269), True, 'import streamlit as st\n'), ((12290, 12380), 'streamlit.file_uploader', 'st.file_uploader', (['"""Upload an audio clip"""'], {'key': '"""end_to_end"""', 'type': "['wav', 'mp3', 'm4a']"}), "('Upload an audio clip', key='end_to_end', type=['wav',\n    'mp3', 'm4a'])\n", (12306, 12380), True, 'import streamlit as st\n'), ((12392, 12423), 'streamlit.form_submit_button', 'st.form_submit_button', (['"""UPLOAD"""'], {}), "('UPLOAD')\n", (12413, 12423), True, 'import streamlit as st\n'), ((16478, 16498), 'serpapi.GoogleSearch', 'GoogleSearch', (['params'], {}), '(params)\n', (16490, 16498), False, 'from serpapi import GoogleSearch\n'), ((16967, 16993), 'streamlit.write', 'st.write', (['"""Coming soon..."""'], {}), "('Coming soon...')\n", (16975, 16993), True, 'import streamlit as st\n'), ((17116, 17169), 'streamlit.warning', 'st.warning', (['"""Please enter your username and password"""'], {}), "('Please enter your username and password')\n", (17126, 17169), True, 'import streamlit as st\n'), ((4080, 4100), 'model.get_answer', 'get_answer', (['question'], {}), '(question)\n', (4090, 4100), False, 'from model import get_answer, aget_answer\n'), ((4875, 4982), 'utils.compose_file_path', 'compose_file_path', (['uploaded_file.name'], {'output_prefix': 'None', 'output_dir': 'audio_input_dir', 'output_ext': 'None'}), '(uploaded_file.name, output_prefix=None, output_dir=\n    audio_input_dir, output_ext=None)\n', (4892, 4982), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((5756, 5878), 'utils.compose_file_path', 'compose_file_path', ([], {'input_file_path': 'uploaded_file.name', 'output_prefix': 'None', 'output_dir': 'audio_input_dir', 'output_ext': 'None'}), '(input_file_path=uploaded_file.name, output_prefix=None,\n    output_dir=audio_input_dir, output_ext=None)\n', (5773, 5878), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((6103, 6114), 'time.time', 'time.time', ([], {}), '()\n', (6112, 6114), False, 'import time\n'), ((6119, 6131), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (6129, 6131), True, 'import streamlit as st\n'), ((6148, 6258), 'utils.compose_file_path', 'compose_file_path', (['audio_file_path'], {'output_prefix': 'None', 'output_dir': 'transcript_input_dir', 'output_ext': '"""txt"""'}), "(audio_file_path, output_prefix=None, output_dir=\n    transcript_input_dir, output_ext='txt')\n", (6165, 6258), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((6324, 6360), 'os.path.exists', 'os.path.exists', (['transcript_file_path'], {}), '(transcript_file_path)\n', (6338, 6360), False, 'import os\n'), ((7582, 7651), 'streamlit.info', 'st.info', (['"""Please add your OPENAI API KEY to environment to continue."""'], {}), "('Please add your OPENAI API KEY to environment to continue.')\n", (7589, 7651), True, 'import streamlit as st\n'), ((7830, 7973), 'utils.compose_file_path', 'compose_file_path', ([], {'input_file_path': 'rewrite_uploaded_file.name', 'output_prefix': '"""rewrite"""', 'output_dir': 'transcript_output_dir', 'output_ext': '"""txt"""'}), "(input_file_path=rewrite_uploaded_file.name, output_prefix\n    ='rewrite', output_dir=transcript_output_dir, output_ext='txt')\n", (7847, 7973), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((8201, 8266), 'langchain.text_splitter.RecursiveCharacterTextSplitter', 'RecursiveCharacterTextSplitter', ([], {'chunk_size': '(1024)', 'chunk_overlap': '(20)'}), '(chunk_size=1024, chunk_overlap=20)\n', (8231, 8266), False, 'from langchain.text_splitter import RecursiveCharacterTextSplitter\n'), ((8924, 8960), 'streamlit.write', 'st.write', (['"""### Rewritten transcript"""'], {}), "('### Rewritten transcript')\n", (8932, 8960), True, 'import streamlit as st\n'), ((10356, 10425), 'streamlit.info', 'st.info', (['"""Please add your OPENAI API KEY to environment to continue."""'], {}), "('Please add your OPENAI API KEY to environment to continue.')\n", (10363, 10425), True, 'import streamlit as st\n'), ((10617, 10757), 'utils.compose_file_path', 'compose_file_path', ([], {'input_file_path': 'summary_uploaded_file.name', 'output_prefix': '"""summary"""', 'output_dir': 'summary_output_dir', 'output_ext': '"""txt"""'}), "(input_file_path=summary_uploaded_file.name, output_prefix\n    ='summary', output_dir=summary_output_dir, output_ext='txt')\n", (10634, 10757), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((10881, 10947), 'langchain.text_splitter.RecursiveCharacterTextSplitter', 'RecursiveCharacterTextSplitter', ([], {'chunk_size': '(1024)', 'chunk_overlap': '(100)'}), '(chunk_size=1024, chunk_overlap=100)\n', (10911, 10947), False, 'from langchain.text_splitter import RecursiveCharacterTextSplitter\n'), ((11047, 11083), 'streamlit.write', 'st.write', (['"""### Summarize transcript"""'], {}), "('### Summarize transcript')\n", (11055, 11083), True, 'import streamlit as st\n'), ((13026, 13060), 'streamlit.write', 'st.write', (['"""### Transcribing audio"""'], {}), "('### Transcribing audio')\n", (13034, 13060), True, 'import streamlit as st\n'), ((13941, 13977), 'streamlit.write', 'st.write', (['"""### Rewritten transcript"""'], {}), "('### Rewritten transcript')\n", (13949, 13977), True, 'import streamlit as st\n'), ((16933, 16954), 'pandas.DataFrame', 'pd.DataFrame', (['content'], {}), '(content)\n', (16945, 16954), True, 'import pandas as pd\n'), ((4132, 4153), 'model.aget_answer', 'aget_answer', (['question'], {}), '(question)\n', (4143, 4153), False, 'from model import get_answer, aget_answer\n'), ((5191, 5236), 'streamlit.spinner', 'st.spinner', (['f"""reading from {audio_file_path}"""'], {}), "(f'reading from {audio_file_path}')\n", (5201, 5236), True, 'import streamlit as st\n'), ((5263, 5309), 'utils.split', 'split', ([], {'in_file_path': 'audio_file_path', 'length': '(10)'}), '(in_file_path=audio_file_path, length=10)\n', (5268, 5309), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((6449, 6508), 'streamlit.spinner', 'st.spinner', (['f"""written transcript to {transcript_file_path}"""'], {}), "(f'written transcript to {transcript_file_path}')\n", (6459, 6508), True, 'import streamlit as st\n'), ((6529, 6577), 'utils.sound2txt', 'sound2txt', (['audio_file_path', 'transcript_file_path'], {}), '(audio_file_path, transcript_file_path)\n', (6538, 6577), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((6584, 6612), 'streamlit.write', 'st.write', (["transcript['text']"], {}), "(transcript['text'])\n", (6592, 6612), True, 'import streamlit as st\n'), ((8970, 9015), 'streamlit.spinner', 'st.spinner', (['f"""written to {rewrite_file_path}"""'], {}), "(f'written to {rewrite_file_path}')\n", (8980, 9015), True, 'import streamlit as st\n'), ((11093, 11138), 'streamlit.spinner', 'st.spinner', (['f"""written to {summary_file_path}"""'], {}), "(f'written to {summary_file_path}')\n", (11103, 11138), True, 'import streamlit as st\n'), ((11164, 11185), 'utils.get_summarize_chain', 'get_summarize_chain', ([], {}), '()\n', (11183, 11185), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((12494, 12538), 'streamlit.spinner', 'st.spinner', (['f"""uploaded {uploaded_file.name}"""'], {}), "(f'uploaded {uploaded_file.name}')\n", (12504, 12538), True, 'import streamlit as st\n'), ((12938, 12984), 'utils.split', 'split', ([], {'in_file_path': 'audio_file_path', 'length': '(10)'}), '(in_file_path=audio_file_path, length=10)\n', (12943, 12984), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((14069, 14134), 'langchain.text_splitter.RecursiveCharacterTextSplitter', 'RecursiveCharacterTextSplitter', ([], {'chunk_size': '(1024)', 'chunk_overlap': '(20)'}), '(chunk_size=1024, chunk_overlap=20)\n', (14099, 14134), False, 'from langchain.text_splitter import RecursiveCharacterTextSplitter\n'), ((6855, 6893), 'os.path.basename', 'os.path.basename', (['transcript_file_path'], {}), '(transcript_file_path)\n', (6871, 6893), False, 'import os\n'), ((9235, 9256), 'streamlit.write', 'st.write', (["res['text']"], {}), "(res['text'])\n", (9243, 9256), True, 'import streamlit as st\n'), ((9263, 9278), 'streamlit.write', 'st.write', (['"""---"""'], {}), "('---')\n", (9271, 9278), True, 'import streamlit as st\n'), ((9599, 9634), 'os.path.basename', 'os.path.basename', (['rewrite_file_path'], {}), '(rewrite_file_path)\n', (9615, 9634), False, 'import os\n'), ((11737, 11772), 'os.path.basename', 'os.path.basename', (['summary_file_path'], {}), '(summary_file_path)\n', (11753, 11772), False, 'import os\n'), ((12616, 12738), 'utils.compose_file_path', 'compose_file_path', ([], {'input_file_path': 'uploaded_file.name', 'output_prefix': 'None', 'output_dir': 'audio_input_dir', 'output_ext': 'None'}), '(input_file_path=uploaded_file.name, output_prefix=None,\n    output_dir=audio_input_dir, output_ext=None)\n', (12633, 12738), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((13262, 13273), 'time.time', 'time.time', ([], {}), '()\n', (13271, 13273), False, 'import time\n'), ((13625, 13673), 'utils.sound2txt', 'sound2txt', (['audio_file_path', 'transcript_file_path'], {}), '(audio_file_path, transcript_file_path)\n', (13634, 13673), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((13682, 13715), 'streamlit.write', 'st.write', (["transcript['text'][:50]"], {}), "(transcript['text'][:50])\n", (13690, 13715), True, 'import streamlit as st\n'), ((13722, 13734), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (13732, 13734), True, 'import streamlit as st\n'), ((15403, 15414), 'time.time', 'time.time', ([], {}), '()\n', (15412, 15414), False, 'import time\n'), ((15613, 15753), 'utils.text2summary', 'text2summary', (['rewrite', 'summary_file_path'], {'instruction': '"""give helpful and concise summary with action items in traditional chinese."""'}), "(rewrite, summary_file_path, instruction=\n    'give helpful and concise summary with action items in traditional chinese.'\n    )\n", (15625, 15753), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((15753, 15770), 'streamlit.write', 'st.write', (['summary'], {}), '(summary)\n', (15761, 15770), True, 'import streamlit as st\n'), ((15777, 15789), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (15787, 15789), True, 'import streamlit as st\n'), ((11506, 11523), 'streamlit.write', 'st.write', (['summary'], {}), '(summary)\n', (11514, 11523), True, 'import streamlit as st\n'), ((11531, 11546), 'streamlit.write', 'st.write', (['"""---"""'], {}), "('---')\n", (11539, 11546), True, 'import streamlit as st\n'), ((13310, 13435), 'utils.compose_file_path', 'compose_file_path', ([], {'input_file_path': 'audio_file_path', 'output_prefix': 'None', 'output_dir': 'transcript_input_dir', 'output_ext': '"""txt"""'}), "(input_file_path=audio_file_path, output_prefix=None,\n    output_dir=transcript_input_dir, output_ext='txt')\n", (13327, 13435), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((14514, 14651), 'utils.compose_file_path', 'compose_file_path', ([], {'input_file_path': 'transcript_file_path', 'output_prefix': '"""rewrite"""', 'output_dir': 'transcript_output_dir', 'output_ext': '"""txt"""'}), "(input_file_path=transcript_file_path, output_prefix=\n    'rewrite', output_dir=transcript_output_dir, output_ext='txt')\n", (14531, 14651), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((15141, 15167), 'streamlit.write', 'st.write', (["res['text'][:50]"], {}), "(res['text'][:50])\n", (15149, 15167), True, 'import streamlit as st\n'), ((15175, 15187), 'streamlit.divider', 'st.divider', ([], {}), '()\n', (15185, 15187), True, 'import streamlit as st\n'), ((15441, 15572), 'utils.compose_file_path', 'compose_file_path', ([], {'input_file_path': 'rewrite_file_path', 'output_prefix': '"""summary"""', 'output_dir': 'summary_output_dir', 'output_ext': '"""txt"""'}), "(input_file_path=rewrite_file_path, output_prefix=\n    'summary', output_dir=summary_output_dir, output_ext='txt')\n", (15458, 15572), False, 'from utils import split, compose_file_path, get_rewrite_chain, get_summarize_chain, sound2txt, text2summary\n'), ((6641, 6652), 'time.time', 'time.time', ([], {}), '()\n', (6650, 6652), False, 'import time\n'), ((13827, 13838), 'time.time', 'time.time', ([], {}), '()\n', (13836, 13838), False, 'import time\n'), ((15867, 15878), 'time.time', 'time.time', ([], {}), '()\n', (15876, 15878), False, 'import time\n'), ((11333, 11365), 'langchain.docstore.document.Document', 'Document', ([], {'page_content': 'paragraph'}), '(page_content=paragraph)\n', (11341, 11365), False, 'from langchain.docstore.document import Document\n')]