Spaces:
Runtime error
Runtime error
Update function.py
Browse files- function.py +123 -16
function.py
CHANGED
|
@@ -1,27 +1,123 @@
|
|
| 1 |
-
from langchain_community.llms import OpenAI
|
| 2 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
-
def get_answers(questions,model):
|
| 8 |
|
| 9 |
-
|
| 10 |
-
answer_prompt = (f"I want you to become a teacher answer this specific Question: {questions}. You should gave me a straightforward and consise explanation and answer to each one of them")
|
| 11 |
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
return(answers)
|
| 25 |
|
| 26 |
|
| 27 |
|
|
@@ -54,6 +150,17 @@ def generate_workshop_details(topic, audience, benefit, date_time):
|
|
| 54 |
if not (topic and audience and benefit and date_time):
|
| 55 |
return "All details are required to generate the workshop information."
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
details = {
|
| 58 |
"Topic": topic,
|
| 59 |
"Audience": audience,
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from langchain.chains import LLMChain, SimpleSequentialChain
|
| 3 |
+
from langchain.memory import ConversationBufferMemory
|
| 4 |
+
from langchain.prompts import PromptTemplate
|
| 5 |
+
from langchain.llms import OpenAI
|
| 6 |
|
| 7 |
|
| 8 |
|
|
|
|
| 9 |
|
| 10 |
+
def ai_generated_content(topic, audience, benefit, date_time):
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
+
|
| 14 |
+
# Initialize the LLM and memory
|
| 15 |
+
llm = OpenAI(model="gpt-4")
|
| 16 |
+
memory = ConversationBufferMemory()
|
| 17 |
+
|
| 18 |
+
# Define the user inputs
|
| 19 |
+
topic = topic
|
| 20 |
+
audience = audience
|
| 21 |
+
benefit_outcome = benefit
|
| 22 |
+
date = date_time
|
| 23 |
+
|
| 24 |
+
# Store the user inputs in memory
|
| 25 |
+
memory.save_context(
|
| 26 |
+
{"input": f"Topic: {topic}, Audience: {audience}, Benefit/Outcome: {benefit_outcome}, Date: {date}"},
|
| 27 |
+
{}
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Define prompt templates
|
| 31 |
+
headline_template = PromptTemplate(
|
| 32 |
+
input_variables=["history"],
|
| 33 |
+
template="Using the details provided: {history}, generate a headline using the format: 'MASTER [specific skill or process] IN [timeframe or tool] USING [method or tool] TO [immediate benefit] AND FINALLY [major goal or habit or benefit], GUARANTEED!'"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
subheadline_template = PromptTemplate(
|
| 37 |
+
input_variables=["history"],
|
| 38 |
+
template="Generate a subheading that reassures the user they don’t need any prior knowledge in {history}. The format should be 'WITHOUT ANY PRIOR [technical skill] OR [domain knowledge].'"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
price_statement_template = PromptTemplate(
|
| 42 |
+
input_variables=["history"],
|
| 43 |
+
template="Generate a short value statement that combines the outcome with the price of the offer. The format should be 'Become an advanced [skill] expert in [price].' Use language that emphasizes the low cost for high-value results."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Create individual chains
|
| 47 |
+
headline_chain = LLMChain(
|
| 48 |
+
llm=llm,
|
| 49 |
+
prompt=headline_template,
|
| 50 |
+
memory=memory,
|
| 51 |
+
output_key="headline"
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
subheadline_chain = LLMChain(
|
| 55 |
+
llm=llm,
|
| 56 |
+
prompt=subheadline_template,
|
| 57 |
+
memory=memory,
|
| 58 |
+
output_key="subheadline"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
price_chain = LLMChain(
|
| 62 |
+
llm=llm,
|
| 63 |
+
prompt=price_statement_template,
|
| 64 |
+
memory=memory,
|
| 65 |
+
output_key="price_statement"
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
# Combine chains into a sequential process
|
| 69 |
+
landing_page_chain = SequentialChain(
|
| 70 |
+
chains=[headline_chain, subheadline_chain, price_chain],
|
| 71 |
+
input_variables=[],
|
| 72 |
+
output_variables=["headline", "subheadline", "price_statement"]
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
# Generate the landing page content
|
| 76 |
+
output = landing_page_chain.run({})
|
| 77 |
+
|
| 78 |
+
# Parsing the outputs into key-value pairs
|
| 79 |
+
landing_page_data = {
|
| 80 |
+
"headline": output["headline"],
|
| 81 |
+
"subheadline": output["subheadline"],
|
| 82 |
+
"price_statement": output["price_statement"]
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
print(landing_page_data)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
|
|
|
|
| 121 |
|
| 122 |
|
| 123 |
|
|
|
|
| 150 |
if not (topic and audience and benefit and date_time):
|
| 151 |
return "All details are required to generate the workshop information."
|
| 152 |
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
ai_generated_content(topic, audience, benefit, date_time)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
|
| 164 |
details = {
|
| 165 |
"Topic": topic,
|
| 166 |
"Audience": audience,
|