abaliyan commited on
Commit
f8fecf8
·
verified ·
1 Parent(s): 5b37c6a

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain.chains import LLMChain
2
+ from langchain_community.llms import OpenAI
3
+ from langchain_core.prompts import PromptTemplate
4
+ import streamlit as st
5
+
6
+ # Set the page to wide mode
7
+ st.set_page_config(layout="wide")
8
+
9
+ mini_template = "You are an expert researcher. You\'ve talked to hundreds of {Target Audience}. \
10
+ Each person in the niche of {Target Audience} has certain struggles that make it easier to sell {My Course}. \
11
+ These are called Pain Points. There's a recipe for getting to the core of the Pain Points of {Target Audience}. \
12
+ Namely, answer each of these Questions 3 times, each getting deeper in the issues of {Target Audience}, \
13
+ appealing to their Emotions and uncertainties related to {My Course}. \
14
+ The Questions (answer each QUESTION 3 times in listicle format according to the instructions):\
15
+ 1. What keeps them awake at night?\
16
+ 2. What are they afraid of?\
17
+ 3. What are they angry about?\
18
+ "
19
+
20
+
21
+ st.title("Saas Application")
22
+
23
+ prompt = PromptTemplate(
24
+ input_variables = ["Target Audience", "My Course"],
25
+ template=mini_template,
26
+ )
27
+
28
+ chain = LLMChain(llm=OpenAI(), prompt=prompt)
29
+
30
+ #target_audience = "professionals looking for course on Power BI"
31
+ #my_course = "Zero to Hero in PowerBI"
32
+
33
+ # Use the sidebar for input
34
+ target_audience = st.sidebar.text_input("Enter your target audience")
35
+ my_course = st.sidebar.text_input("Enter your course name")
36
+
37
+ if st.sidebar.button("Get response"):
38
+ if target_audience and my_course:
39
+ with st.spinner("Generating response..."):
40
+ with st.expander("Show prompt", expanded=False):
41
+ st.info(prompt.template)
42
+ answer = chain.run({"Target Audience": target_audience, "My Course": my_course})
43
+
44
+ # Split the 'answer' into sections based on the questions
45
+ sections = [section.strip() for section in answer.split("\n\n") if section.strip() != ""]
46
+
47
+ # Assuming there are exactly three sections based on your output structure
48
+ if len(sections) == 3:
49
+ # Extract titles for tabs
50
+ titles = [section.split('\n')[0] for section in sections]
51
+
52
+ # Extract content for each section, removing the title
53
+ contents = [section.split('\n')[1:] for section in sections]
54
+
55
+ # Create tabs for each category
56
+ tabs = st.tabs(titles)
57
+
58
+ for i, tab in enumerate(tabs):
59
+ with tab:
60
+ st.header(titles[i])
61
+ for content in contents[i]:
62
+ st.markdown(content)
63
+ else:
64
+ st.error("The answer format does not match the expected structure.")
65
+ st.success("Hope you like the response.❤")
66
+ elif target_audience:
67
+ st.error("Enter your course name.")
68
+ elif my_course:
69
+ st.error("Enter your target audience.")
70
+ else:
71
+ st.error("No input detected, Please provide the desired information.")