diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..8cafa45 Binary files /dev/null and b/.DS_Store differ diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e5292b0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "CodeGPT.query.language": "Spanish" +} \ No newline at end of file diff --git a/langchain_examples/.DS_Store b/langchain_examples/.DS_Store new file mode 100644 index 0000000..7c95b49 Binary files /dev/null and b/langchain_examples/.DS_Store differ diff --git a/langchain_examples/.env b/langchain_examples/.env new file mode 100644 index 0000000..ed9717a --- /dev/null +++ b/langchain_examples/.env @@ -0,0 +1 @@ +openai_api_key=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 \ No newline at end of file diff --git a/langchain_examples/youtube_TLDR.py b/langchain_examples/youtube_TLDR.py index 5e8b658..c293783 100644 --- a/langchain_examples/youtube_TLDR.py +++ b/langchain_examples/youtube_TLDR.py @@ -1,8 +1,9 @@ -from dotenv import dotenv_values -import os +import streamlit as st +#from dotenv import load_dotenv from langchain.document_loaders import YoutubeLoader from langchain.chat_models import ChatOpenAI from langchain.llms import OpenAI +from streamlit_chat import message from langchain.prompts.chat import ( ChatPromptTemplate, SystemMessagePromptTemplate, @@ -10,55 +11,61 @@ HumanMessagePromptTemplate, ) -import streamlit as st -from streamlit_chat import message - +#load_dotenv() #load environment variables from .env file +gpt_v = ChatOpenAI(temperature=0.4, model_name='gpt-3.5-turbo',openai_api_key="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") # create ChatOpenAI instance +#gpt_v = ChatOpenAI(temperature=0.5, max_tokens=1000, engine="gpt-3.5", openai_api_key="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") -api_keys=dotenv_values() -os.environ['OPENAI_API_KEY'] = dotenv_values()['openai_api_key'] #set environment variable def summarize_video(video_url): - loader = YoutubeLoader.from_youtube_url(video_url, add_video_info=False) - system_prompt_template = """You are Youtube Summarizer and you specialize in making short and consice summaries for any youtube videos. Use the provided transcription to create a summary of what the video is about. - """ - human_prompt_template = "Provide a short and concise summary of the following transcript: {text}." - system_message_prompt = SystemMessagePromptTemplate.from_template(system_prompt_template) - human_message_prompt = HumanMessagePromptTemplate.from_template(human_prompt_template) - # delete the gpt-4 model_name to use the default gpt-3.5 turbo for faster results - gpt_4 = ChatOpenAI(temperature=.02, model_name='gpt-4') - conversation = [system_message_prompt, human_message_prompt] - chat_prompt = ChatPromptTemplate.from_messages(conversation) - response = gpt_4(chat_prompt.format_prompt( - text=loader.load()[0].page_content).to_messages()) - return response + try: + loader = YoutubeLoader.from_youtube_channel(video_url, add_video_info=False) + system_prompt_template = "Eres Youtube Resumidor y te especializas en hacer resúmenes cortos y concisos para cualquier video de YouTube. Use la transcripción provista para crear un resumen de lo que trata el video." + human_prompt_template = "Proporcione un breve y conciso resumen en español, de la siguiente transcripción: {text}." + system_message_prompt = SystemMessagePromptTemplate.from_template(system_prompt_template) + human_message_prompt = HumanMessagePromptTemplate.from_template(human_prompt_template) + conversation = [system_message_prompt, human_message_prompt] + chat_prompt = ChatPromptTemplate.from_messages(conversation) + response = gpt_v(chat_prompt.format_prompt(text=loader.load()[0].page_content).to_messages()) + return response + except Exception as e: + st.warning(f"Ocurrió un error al resumir el video: {str(e)}, video_url: {video_url}") st.set_page_config( - page_title="Youtube TL;DR", + page_title="Resumen Youtube (Neocortex)", page_icon=":robot:" ) -st.header("Youtube TL;DR :robot_face:") +st.header("Resumen VIDEITOS Youtube (Neocortex) :robot_face:") if 'ai' not in st.session_state: st.session_state['ai'] = [] if 'human' not in st.session_state: st.session_state['human'] = [] - -def get_text(): - input_text = st.text_input('Enter Youtube video URL to get TL;DR:', key='input', placeholder='Youtube URL') - return input_text +def get_text(): + try: + input_text = st.text_input('Digita la direccion URL del Video de Youtube', + key='input', placeholder='Youtube URL') + if input_text.startswith('https://www.youtube.com') or input_text.startswith('https://youtu.be'): + return input_text + else: + st.warning('¡Por favor, ingresa una dirección URL de YouTube válida!') + except: + st.warning('Error al ingresar la dirección URL') -user_input=get_text() +user_input = get_text() if user_input: - output = summarize_video(user_input).content - - st.session_state['human'].append(user_input) - st.session_state['ai'].append(output) - -if st.session_state['ai']: - for i in range(len(st.session_state['ai']) -1, -1, -1): - message(st.session_state['ai'][i], key=str(i)) - message(st.session_state['human'][i], is_user=True, key=str(i) + '_user') - + try: + output = summarize_video(user_input).content + st.session_state['human'].append(user_input) + st.session_state['ai'].append(output) + except Exception as e: + st.error(f"Error resumiendo el video: {e}") +if st.session_state.get('ai'): + for i, ai_message in enumerate(st.session_state['ai'][::-1]): + try: + message(ai_message, key=str(i)) + message(st.session_state['human'][::-1][i], is_user=True, key=str(i) + '_user') + except Exception as e: + st.error(f"Error mostrando mensaje: {e}") diff --git a/stock_chart/.DS_Store b/stock_chart/.DS_Store new file mode 100644 index 0000000..9146a28 Binary files /dev/null and b/stock_chart/.DS_Store differ