yvoievid commited on
Commit
10f51c3
Β·
1 Parent(s): c6c9ebf

[init] Added system prompt, streamlit base, requirements

Browse files
Files changed (2) hide show
  1. app.py +64 -0
  2. reqirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from langchain_openai import ChatOpenAI
3
+ from langchain_core.prompts import ChatPromptTemplate
4
+ from langchain.schema import StrOutputParser
5
+
6
+ chat_llm = ChatOpenAI(
7
+ openai_api_key=st.secrets["OPENAI_API_KEY"],
8
+ model=st.secrets["OPENAI_MODEL"],
9
+ )
10
+
11
+ caption_examples_file_path = "./data/caption_examples.txt"
12
+
13
+ prompt = ChatPromptTemplate.from_messages(
14
+ [
15
+ (
16
+ "system",
17
+ "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",
18
+ ),
19
+ ( "system", "{example}" ),
20
+ ( "human", "{question}" ),
21
+ ]
22
+ )
23
+
24
+ chat_chain = prompt | chat_llm | StrOutputParser()
25
+
26
+ with open(caption_examples_file_path, "r") as file:
27
+ caption_examples = file.read()
28
+
29
+
30
+ if "visibility" not in st.session_state:
31
+ st.session_state.visibility = "visible"
32
+ st.session_state.disabled = False
33
+ st.session_state.placeholder = "What Instagram post should be about?"
34
+
35
+
36
+ st.set_page_config(
37
+ page_title="Backpack title generator",
38
+ page_icon="πŸ‘‹",
39
+ )
40
+ st.write("# Welcome to InstaGPT! πŸ‘‹")
41
+ st.markdown("""Writes caption for a desired backpacks in style of Osprey""")
42
+
43
+
44
+ text_input = st.text_input(
45
+ "Enter some text πŸ‘‡",
46
+ label_visibility=st.session_state.visibility,
47
+ disabled=st.session_state.disabled,
48
+ placeholder=st.session_state.placeholder,
49
+ )
50
+ generate_respose = st.button("Generate")
51
+ if text_input:
52
+ st.write("You entered: ", text_input)
53
+
54
+
55
+ if generate_respose:
56
+ response = chat_chain.invoke(
57
+ {
58
+ "example": caption_examples,
59
+ "question": text_input,
60
+ }
61
+ )
62
+
63
+ st.write("Generated: ", response)
64
+
reqirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ langchain==0.2.1
2
+ langchain-community==0.2.1
3
+ langchain-core==0.2.1
4
+ langchain-openai==0.1.7
5
+ langchain-text-splitters==0.2.0
6
+ langchainhub==0.1.16
7
+ openai==1.30.3