Spaces:
Sleeping
Sleeping
File size: 2,312 Bytes
10f51c3 9e4b615 10f51c3 9e4b615 10f51c3 b429427 10f51c3 |
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 64 65 66 67 68 69 70 71 72 73 |
import streamlit as st
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain.schema import StrOutputParser
chat_llm = ChatOpenAI(
openai_api_key=st.secrets["OPENAI_API_KEY"],
model=st.secrets["OPENAI_MODEL"],
)
caption_examples_file_path = "./data/caption_examples.txt"
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a instagram post writer and you writing captions for posts for company that make hiking and bicycle backpacks. Responde with 2 sentence max, use context as example",
),
( "system", "{example}" ),
( "human", "{question}" ),
]
)
chat_chain = prompt | chat_llm | StrOutputParser()
with open(caption_examples_file_path, "r") as file:
caption_examples = file.read()
if "visibility" not in st.session_state:
st.session_state.visibility = "visible"
st.session_state.disabled = False
st.session_state.placeholder = "Example: Generate post about backpack Black Mamba with volume of 22 liters"
st.set_page_config(
page_title="Backpack title generator",
page_icon="π",
)
st.write("# Welcome to InstaGPT! π")
st.markdown("""Writes caption for a desired backpacks in style of Osprey""")
text_input = st.text_input(
"Enter some text π",
label_visibility=st.session_state.visibility,
disabled=st.session_state.disabled,
placeholder=st.session_state.placeholder,
)
predefined_strings = ["Generate post about backpack Black Mamba with volume of 22 liters", "Write a post about giveaway of 3 backpacks from new collection", "Create new post about backpack Adventure for 250 dollars"]
st.write("Examples: \n\n Generate post about backpack Black Mamba with volume of 22 liters \n\n Write a post about giveaway of 3 backpacks from new collection \n\n Create new post about backpack Adventure for 250 dollars")
generate_respose = st.button("Generate")
if text_input:
st.write("You entered: ", text_input)
if generate_respose:
if text_input == "":
st.write("Enter something")
else:
response = chat_chain.invoke(
{
"example": caption_examples,
"question": text_input,
}
)
st.write("Generated: ", response)
|