amaltese commited on
Commit
5525786
·
verified ·
1 Parent(s): 4140b01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -6
app.py CHANGED
@@ -13,12 +13,30 @@ def get_wikipedia_summary(name):
13
  page = wiki_wiki.page(name)
14
  return page.summary if page.exists() else "Sorry, I couldn't find information on that historical figure."
15
 
16
- def generate_response(person_name, user_input, context):
17
- """Generate a dynamic response based on the Wikipedia summary and user input."""
18
- if any(word in user_input.lower() for word in ["who", "what", "when", "where", "why", "how"]):
19
- return f"{person_name}: {context}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  else:
21
- return f"{person_name}: That is an interesting thought. Could you elaborate?"
22
 
23
  st.title("Chat with a Historical Figure!")
24
 
@@ -30,5 +48,5 @@ if person_name:
30
 
31
  user_input = st.text_input("Ask a question:")
32
  if user_input:
33
- response = generate_response(person_name, user_input, summary)
34
  st.write(f"**{person_name}:** {response}")
 
13
  page = wiki_wiki.page(name)
14
  return page.summary if page.exists() else "Sorry, I couldn't find information on that historical figure."
15
 
16
+ def generate_persona_response(person_name, user_input, context):
17
+ """Generate a persona-based response based on the Wikipedia summary."""
18
+ persona_responses = {
19
+ "Genghis Khan": [
20
+ "Fishing? A peaceful pursuit, but my mind was always on conquest.",
21
+ "The rivers of the steppe were not for leisure but for strategy.",
22
+ "A warrior has little time for such pastimes. Tell me, do you seek power?"
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 f"As {person_name}, I must say—that is an interesting question. History has recorded much about my life. What else do you wish to know?"
40
 
41
  st.title("Chat with a Historical Figure!")
42
 
 
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.write(f"**{person_name}:** {response}")