amaltese commited on
Commit
ebf07f4
·
verified ·
1 Parent(s): 4031494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
app.py CHANGED
@@ -14,18 +14,17 @@ def get_wikipedia_summary(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
- 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!")
 
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 response based on the Wikipedia summary dynamically."""
18
+ sentences = context.split('.')
19
+ relevant_info = [sentence for sentence in sentences if any(word in sentence.lower() for word in user_input.lower().split())]
20
+
21
+ if relevant_info:
22
+ return random.choice(relevant_info) + '.'
 
23
  else:
24
  return random.choice([
25
+ f"An interesting question. I have much knowledge to share—what else do you wish to know?",
26
+ f"Tell me, why does this interest you? Perhaps we may discover more together.",
27
+ f"My life was complex and filled with challenges. Ask again, and I shall elaborate."
28
  ])
29
 
30
  st.title("Chat with a Historical Figure!")