Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,23 +9,30 @@ wiki_wiki = wikipediaapi.Wikipedia(
|
|
9 |
)
|
10 |
|
11 |
def get_wikipedia_summary(name):
|
12 |
-
"""Retrieve and
|
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
|
18 |
-
|
19 |
-
relevant_info = [sentence for sentence in sentences if any(word in sentence.lower() for word in user_input.lower().split())]
|
20 |
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
else:
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
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 |
|