beta_test
Browse files
app.py
CHANGED
@@ -13,9 +13,66 @@ def main():
|
|
13 |
input2 = st.text_input("A tone or a writer's style to shape the story")
|
14 |
input3 = st.text_input("The final language for translating the text")
|
15 |
|
16 |
-
|
|
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
if __name__ == "__main__":
|
21 |
main()
|
|
|
13 |
input2 = st.text_input("A tone or a writer's style to shape the story")
|
14 |
input3 = st.text_input("The final language for translating the text")
|
15 |
|
16 |
+
if st.button("Generate"):
|
17 |
+
result = process_input(input1, input2, input3)
|
18 |
+
st.markdown(f"<div>{result}</div>", unsafe_allow_html = True)
|
19 |
|
20 |
+
def process_input(a, b, c):
|
21 |
+
model = ChatOpenAI(model = "gpt-4o-mini")
|
22 |
+
|
23 |
+
# Chain 1
|
24 |
+
prompt_one = PromptTemplate(
|
25 |
+
input_variables = ["object"],
|
26 |
+
template = "A story about {object}",
|
27 |
+
)
|
28 |
|
29 |
+
chain_one = LLMChain(
|
30 |
+
llm = model,
|
31 |
+
prompt = prompt_one,
|
32 |
+
output_key = "story"
|
33 |
+
)
|
34 |
+
|
35 |
+
# Chain 2
|
36 |
+
prompt_two = PromptTemplate(
|
37 |
+
input_variables = ["style", "story"],
|
38 |
+
template = "You are a professional writer. You will be given a short story and you will inspire from this original story and create a new story in {style} style. The original story: {story}.",
|
39 |
+
)
|
40 |
+
|
41 |
+
chain_two = LLMChain(
|
42 |
+
llm = model,
|
43 |
+
prompt = prompt_two,
|
44 |
+
output_key = "expanded_story"
|
45 |
+
|
46 |
+
)
|
47 |
+
|
48 |
+
# Chain 3
|
49 |
+
prompt_three = PromptTemplate(
|
50 |
+
input_variables = ["expanded_story", "language"],
|
51 |
+
template = "Translate the story: {expanded_story} into {language}?".
|
52 |
+
)
|
53 |
+
|
54 |
+
chain_three = LLMChain(
|
55 |
+
llm = model,
|
56 |
+
prompt = prompt_three,
|
57 |
+
output_key = "translated"
|
58 |
+
|
59 |
+
)
|
60 |
+
|
61 |
+
# SEQUENCE
|
62 |
+
final_chain = SequentialChain(
|
63 |
+
chains = [chain_one, chain_two, chain_three],
|
64 |
+
input_variables = ["object", "style", "language"],
|
65 |
+
output_variables = ["translated"],
|
66 |
+
verbose = True
|
67 |
+
)
|
68 |
+
|
69 |
+
resp = final_chain({
|
70 |
+
"object": a,
|
71 |
+
"style":b,
|
72 |
+
"language": c
|
73 |
+
})
|
74 |
+
|
75 |
+
return resp["translated"]
|
76 |
|
77 |
if __name__ == "__main__":
|
78 |
main()
|