Spaces:
Runtime error
Runtime error
File size: 2,348 Bytes
50be1ff 9162cf1 515f567 377f9ae 9162cf1 515f567 66e7727 9162cf1 b7f6cd9 61a50a8 515f567 377f9ae 515f567 66e7727 377f9ae 515f567 377f9ae 61a50a8 377f9ae 61a50a8 377f9ae 66e7727 515f567 50be1ff 515f567 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
import streamlit as st
import os
import getpass
from langchain import PromptTemplate
from langchain import hub
from langchain.docstore.document import Document
from langchain.document_loaders import WebBaseLoader
from langchain.schema import StrOutputParser
from langchain.schema.prompt_template import format_document
from langchain.schema.runnable import RunnablePassthrough
from langchain.vectorstores import Chroma
import google.generativeai as genai
from langchain_google_genai import GoogleGenerativeAIEmbeddings
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.chains.llm import LLMChain
from langchain.chains import StuffDocumentsChain
GOOGLE_API_KEY=os.environ['GOOGLE_API_KEY']
url_user = st.text_input("Enter Url","https://www.moneycontrol.com/stocksmarketsindia/")
loader = WebBaseLoader(url_user)
docs = loader.load()
gemini_embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
llm = ChatGoogleGenerativeAI(model="gemini-pro",google_api_key = GOOGLE_API_KEY)
# user_prompt = st.text_input("Enter Prompt","What is the best stocks for the next few weeks")
llm_prompt_template = """You are an expert Stock Market Trader for stock market insights.
Based on the context below
{context}, Suggest some stocks recommendations"""
st.write(llm_prompt_template)
llm_prompt = PromptTemplate.from_template(llm_prompt_template)
llm_chain = LLMChain(llm=llm,prompt=llm_prompt)
stuff_chain = StuffDocumentsChain(llm_chain=llm_chain,document_variable_name="context")
res = stuff_chain.invoke(docs)
st.write(res.output_text)
# If there is no environment variable set for the API key, you can pass the API
# key to the parameter `google_api_key` of the `GoogleGenerativeAIEmbeddings`
# function: `google_api_key = "key"`.
# gemini_embeddings = GoogleGenerativeAIEmbeddings(model="models/embedding-001")
# # Save to disk
# vectorstore = Chroma.from_documents(
# documents=docs, # Data
# embedding=gemini_embeddings, # Embedding model
# persist_directory="./chroma_db" # Directory to save data
# )
# vectorstore_disk = Chroma(
# persist_directory="./chroma_db", # Directory of db
# embedding_function=gemini_embeddings # Embedding model |