Ashar086 commited on
Commit
e96ded7
·
verified ·
1 Parent(s): 7a4f365

Update components/historical_personalities.py

Browse files
components/historical_personalities.py CHANGED
@@ -5,6 +5,11 @@ def show_historical_personalities():
5
  st.title("Interact with Historical Personalities")
6
  st.write("Engage in dynamic, educational dialogues with AI-generated historical figures.")
7
 
 
 
 
 
 
8
  personality = st.selectbox("Choose a historical personality", ["Albert Einstein", "William Shakespeare", "Cleopatra", "Leonardo da Vinci", "Marie Curie"])
9
  user_input = st.text_input("Ask a question or start a conversation:")
10
 
@@ -12,14 +17,22 @@ def show_historical_personalities():
12
  if user_input:
13
  with st.spinner(f"Generating response from {personality}..."):
14
  response = generate_historical_dialogue(personality, user_input)
15
- st.write(f"{personality}: {response}")
 
 
 
 
 
 
16
  else:
17
  st.warning("Please enter a question or statement to start the conversation.")
18
 
19
- if 'conversation_history' not in st.session_state:
20
- st.session_state.conversation_history = []
21
-
22
  if len(st.session_state.conversation_history) > 0:
23
  st.subheader("Conversation History")
24
  for entry in st.session_state.conversation_history:
25
  st.text(entry)
 
 
 
 
 
5
  st.title("Interact with Historical Personalities")
6
  st.write("Engage in dynamic, educational dialogues with AI-generated historical figures.")
7
 
8
+ # Initialize the conversation history in session state
9
+ if 'conversation_history' not in st.session_state:
10
+ st.session_state.conversation_history = []
11
+
12
+ # User selects a personality and enters a question
13
  personality = st.selectbox("Choose a historical personality", ["Albert Einstein", "William Shakespeare", "Cleopatra", "Leonardo da Vinci", "Marie Curie"])
14
  user_input = st.text_input("Ask a question or start a conversation:")
15
 
 
17
  if user_input:
18
  with st.spinner(f"Generating response from {personality}..."):
19
  response = generate_historical_dialogue(personality, user_input)
20
+
21
+ # Update conversation history
22
+ st.session_state.conversation_history.append(f"You: {user_input}")
23
+ st.session_state.conversation_history.append(f"{personality}: {response}")
24
+
25
+ # Display the response
26
+ st.write(f"{personality}: {response}")
27
  else:
28
  st.warning("Please enter a question or statement to start the conversation.")
29
 
30
+ # Display the conversation history
 
 
31
  if len(st.session_state.conversation_history) > 0:
32
  st.subheader("Conversation History")
33
  for entry in st.session_state.conversation_history:
34
  st.text(entry)
35
+
36
+ # Run the function to start the Streamlit app
37
+ if __name__ == "__main__":
38
+ show_historical_personalities()