- Authors
- Name
- KAUSTUBH SHARMA
Overview
Table of Contents
Go to Visual Studio Code.
Install streamlit using pip.
- You can use the copy button in the box below to automatically copy its code:
command
pip3 install streamlit
Create a new file "genai_app.py".
Add the import statements inside "genai_app.py" to use Streamlit elements.
genai_app.py
import streamlit as st #all streamlit commands will be available through the "st" alias
- Set the HTML title tag which will be shown in the browser tab.
genai_app.py
import streamlit as st #all streamlit commands will be available through the "st" alias
st.set_page_config(page_title="Text Generator- Gen AI Project") #HTML title1
- Add the page title which will appear on web page.
genai_app.py
import streamlit as st #all streamlit commands will be available through the "st" alias
st.set_page_config(page_title="Text Generator- Gen AI Project") #HTML title
st.title("Text Generator- Gen AI Project") #page title
- Create a multiline text box for prompt input.
genai_app.py
import streamlit as st #all streamlit commands will be available through the "st" alias
st.set_page_config(page_title="Text Generator- Gen AI Project by KAUSTUBH SHARMA") #HTML title
st.title("Text Generator- Gen AI Project") #page title
input_text = st.text_area("Input text", label_visibility="collapsed") #display a multiline text box with no label
- Create button to get the user's prompt and send it to Bedrock.
genai_app.py
import streamlit as st #all streamlit commands will be available through the "st" alias
st.set_page_config(page_title="Text Generator- Gen AI Project by KAUSTUBH SHARMA") #HTML title
st.title("Text Generator- Gen AI Project") #page title
input_text = st.text_area("Input text", label_visibility="collapsed") #display a multiline text box with no label
go_button = st.button("Go", type="primary") #display a primary button
Create a new file "genai_lib.py".
Install langchain using pip.
- You can use the copy button in the box below to automatically copy its code:
bash
pip3 install langchain
Add the import statements inside "genai_lib.py" to use LangChain to call Bedrock and read environment variables.
- You can use the copy button in the box below to automatically copy its code:
genai_lib.py
from langchain_community.llms import Bedrock
- Create a function to call Bedrock
genai_lib.py
def get_text_response(input_content): #text-to-text client function
llm = Bedrock( #create a Bedrock llm client
model_id="cohere.command-text-v14", #set your foundation model here
model_kwargs={
"max_tokens": 512,
"temperature": 0,
"p": 0.01,
"k": 0,
"stop_sequences": [],
"return_likelihoods": "NONE"
}
)
return llm.invoke(input_content) #return a response to the prompt