Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -15,38 +15,39 @@ def get_wikipedia_summary(name):
|
|
15 |
|
16 |
def generate_persona_response(person_name, user_input, context):
|
17 |
"""Generate a persona-based response based on the Wikipedia summary."""
|
18 |
-
|
19 |
-
"
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
"Thomas Jefferson": [
|
25 |
-
"Ah, the beauty of nature! I often found solace in Monticello’s gardens.",
|
26 |
-
"A fine question. One must balance duty with pleasure.",
|
27 |
-
"Indeed, the world is full of wonders. How do you spend your leisure time?"
|
28 |
-
],
|
29 |
-
"Marie Curie": [
|
30 |
-
"Fishing? No, my passion lay in the pursuit of knowledge.",
|
31 |
-
"The only elements I fished for were those unseen by the human eye.",
|
32 |
-
"Curiosity, much like science, leads us to unexpected places. What interests you?"
|
33 |
-
]
|
34 |
-
}
|
35 |
-
|
36 |
-
if person_name in persona_responses:
|
37 |
-
return random.choice(persona_responses[person_name])
|
38 |
else:
|
39 |
-
return
|
|
|
|
|
|
|
|
|
40 |
|
41 |
st.title("Chat with a Historical Figure!")
|
42 |
|
43 |
# User inputs a historical figure
|
|
|
|
|
|
|
|
|
|
|
44 |
person_name = st.text_input("Enter the name of a historical figure:")
|
45 |
-
if person_name:
|
46 |
-
|
47 |
-
st.
|
48 |
-
|
|
|
|
|
49 |
user_input = st.text_input("Ask a question:")
|
50 |
if user_input:
|
51 |
-
response = generate_persona_response(person_name, user_input, summary)
|
52 |
-
st.
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def generate_persona_response(person_name, user_input, context):
|
17 |
"""Generate a persona-based response based on the Wikipedia summary."""
|
18 |
+
if "battle" in user_input.lower() or "war" in user_input.lower():
|
19 |
+
return f"War is the path to power. I conquered vast lands through strategy and strength. What more do you wish to know?"
|
20 |
+
elif "family" in user_input.lower():
|
21 |
+
return f"Family is the foundation of a strong empire. My sons carried forth my legacy. What about your family?"
|
22 |
+
elif "travel" in user_input.lower():
|
23 |
+
return f"My armies rode thousands of miles across mountains and deserts. Do you seek adventure?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
else:
|
25 |
+
return random.choice([
|
26 |
+
f"A curious question. Tell me, why does this interest you?",
|
27 |
+
f"The steppes were harsh, yet they shaped me. Tell me more of your world.",
|
28 |
+
f"I have conquered many lands, yet the mind is the greatest battlefield. What is your next question?"
|
29 |
+
])
|
30 |
|
31 |
st.title("Chat with a Historical Figure!")
|
32 |
|
33 |
# User inputs a historical figure
|
34 |
+
if "chat_history" not in st.session_state:
|
35 |
+
st.session_state.chat_history = []
|
36 |
+
st.session_state.summary = ""
|
37 |
+
st.session_state.person_name = ""
|
38 |
+
|
39 |
person_name = st.text_input("Enter the name of a historical figure:")
|
40 |
+
if person_name and not st.session_state.person_name:
|
41 |
+
st.session_state.person_name = person_name
|
42 |
+
st.session_state.summary = get_wikipedia_summary(person_name)
|
43 |
+
st.session_state.chat_history.append((person_name, "I am here. Ask what you wish."))
|
44 |
+
|
45 |
+
if st.session_state.person_name:
|
46 |
user_input = st.text_input("Ask a question:")
|
47 |
if user_input:
|
48 |
+
response = generate_persona_response(st.session_state.person_name, user_input, st.session_state.summary)
|
49 |
+
st.session_state.chat_history.append(("You", user_input))
|
50 |
+
st.session_state.chat_history.append((st.session_state.person_name, response))
|
51 |
+
|
52 |
+
for speaker, message in st.session_state.chat_history:
|
53 |
+
st.write(f"**{speaker}:** {message}")
|