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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -9,23 +9,30 @@ wiki_wiki = wikipediaapi.Wikipedia(
9
  )
10
 
11
  def get_wikipedia_summary(name):
12
- """Retrieve and summarize the Wikipedia page for a given historical figure."""
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 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!")
31
 
 
9
  )
10
 
11
  def get_wikipedia_summary(name):
12
+ """Retrieve and store the Wikipedia page summary for a historical figure."""
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 conversational response based on user input and historical context."""
18
+ user_input = user_input.lower()
 
19
 
20
+ hobby_keywords = ["hobby", "free time", "fun", "leisure", "relax"]
21
+ politics_keywords = ["government", "law", "president", "policy", "rights"]
22
+ war_keywords = ["battle", "war", "fight", "military", "enemy"]
23
+
24
+ if any(word in user_input for word in hobby_keywords):
25
+ return f"Ah, leisure! In my time, I enjoyed reading, studying science, and tending to my gardens. What do you do for leisure?"
26
+ elif any(word in user_input for word in politics_keywords):
27
+ return f"Politics is a fascinating matter. I strongly believed in individual liberty and self-governance. What are your thoughts on democracy?"
28
+ elif any(word in user_input for word in war_keywords):
29
+ return f"Conflict is often necessary to secure freedom. I played my role in the Revolution to help shape a new nation. What do you know of it?"
30
  else:
31
+ relevant_sentences = [s.strip() for s in context.split('.') if any(word in s.lower() for word in user_input.split())]
32
+ if relevant_sentences:
33
+ return random.choice(relevant_sentences) + '.'
34
+ else:
35
+ return f"That is an interesting question. Could you elaborate on what you mean?"
36
 
37
  st.title("Chat with a Historical Figure!")
38