DronA23 commited on
Commit
9d90fdc
Β·
verified Β·
1 Parent(s): ac605ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -83
app.py CHANGED
@@ -2,8 +2,7 @@ import asyncio
2
  import streamlit as st
3
  import os
4
  import pandas as pd
5
- from together import Together
6
- from helper import *
7
 
8
  st.set_page_config(layout="wide")
9
  st.title("Duel Agent Simulation πŸ¦™πŸ¦™")
@@ -12,24 +11,16 @@ with st.sidebar:
12
  with st.expander("Instruction Manual"):
13
  st.markdown("""
14
  # πŸ¦™πŸ¦™ Duel Agent Simulation Streamlit App
15
-
16
  ## Overview
17
-
18
  Welcome to the **Duel Agent Simulation** app! This Streamlit application allows you to chat with Meta's Llama3 model in a unique interview simulation. The app features two agents in an interview scenario, with a judge providing feedback. The best part? You simply provide a topic, and the simulation runs itself!
19
-
20
  ## Features
21
-
22
  ### πŸ“ Instruction Manual
23
-
24
  **Meta Llama3 πŸ¦™ Chatbot**
25
-
26
  This application lets you interact with Meta's Llama3 model through a fun interview-style chat.
27
-
28
  **How to Use:**
29
  1. **Input:** Type a topic into the input box labeled "Enter a topic".
30
- 2. **Submit:** Press the "Submit" button to start the simulation.
31
  3. **Chat History:** View the previous conversations as the simulation unfolds.
32
-
33
  **Credits:**
34
  - **Developer:** Kethan Dosapati
35
  - [LinkedIn](https://www.linkedin.com/in/kethan-dosapati/)
@@ -44,11 +35,22 @@ with st.sidebar:
44
  # Add a button to clear the session state
45
  if st.button("Clear Session"):
46
  st.session_state.messages = []
 
47
  st.experimental_rerun()
48
 
49
  # Initialize chat history
50
  if "messages" not in st.session_state:
51
  st.session_state.messages = []
 
 
 
 
 
 
 
 
 
 
52
 
53
  # Display chat messages from history on app rerun
54
  for message in st.session_state.messages:
@@ -61,82 +63,68 @@ interviewee = call_llama
61
  judge = call_llama
62
 
63
  # React to user input
64
- iter = 0
65
- list_of_iters = []
66
- list_of_questions = []
67
- list_of_answers = []
68
- list_of_judge_comments = []
69
- list_of_passes = []
70
  if submit_button:
71
-
72
- # Initiatization
73
  prompt = f"Ask a question about this topic: {user_topic}"
74
 
75
  # Display user message in chat message container
76
- # Default: user=interviewee, assistant=interviewer
77
- st.chat_message("user").markdown(prompt)
78
- st.session_state.messages.append({"role": "user", "content": prompt})
79
-
80
- while True:
81
-
82
- # Interview asks a question
83
- question = interviewer(prompt)
84
-
85
- # Display assistant response in chat message container
86
- st.chat_message("assistant").markdown(question)
87
- st.session_state.messages.append({"role": "assistant", "content": question})
88
-
89
- # Interviewee attempts an answer
90
- if iter < 5:
91
- answer = interviewee(
92
- f"""
93
- Answer the question: {question} in a mediocre way
94
- Because you are an inexperienced interviewee.
95
- """
96
- )
97
- st.chat_message("user").markdown(answer)
98
- st.session_state.messages.append({"role": "user", "content": answer})
99
- else:
100
- answer = interviewee(
101
- f"""
102
- Answer the question: {question} in a mediocre way
103
- Because you are an inexperienced interviewee but you really want to learn,
104
- so you learn from the judge comments: {judge_comments}
105
- """
106
- )
107
  st.chat_message("user").markdown(answer)
108
  st.session_state.messages.append({"role": "user", "content": answer})
109
 
110
- # Judge thinks and advises but the thoughts are hidden
111
- judge_comments = judge(
112
- f"""
113
- The question is: {question}
114
- The answer is: {answer}
115
- Provide feedback and rate the answer from 1 to 10 while 10 being the best and 1 is the worst.
116
- """
117
- )
118
-
119
- # Collect all responses
120
- passed_or_not = 1 if '8' in judge_comments else 0
121
- list_of_iters.append(iter)
122
- list_of_questions.append(question)
123
- list_of_answers.append(answer)
124
- list_of_judge_comments.append(judge_comments)
125
- list_of_passes.append(passed_or_not)
126
- results_tab = pd.DataFrame({
127
- "Iter.": list_of_iters,
128
- "Questions": list_of_questions,
129
- "Answers": list_of_answers,
130
- "Judge Comments": list_of_judge_comments,
131
- "Passed": list_of_passes
132
- })
133
-
134
- with st.expander("See explanation"):
135
- st.table(results_tab)
136
-
137
- # Stopping rule
138
- if '8' in judge_comments:
139
- break
140
-
141
- # Checkpoint
142
- iter += 1
 
 
 
 
2
  import streamlit as st
3
  import os
4
  import pandas as pd
5
+ from helper import call_llama # Make sure this is properly defined in helper.py
 
6
 
7
  st.set_page_config(layout="wide")
8
  st.title("Duel Agent Simulation πŸ¦™πŸ¦™")
 
11
  with st.expander("Instruction Manual"):
12
  st.markdown("""
13
  # πŸ¦™πŸ¦™ Duel Agent Simulation Streamlit App
 
14
  ## Overview
 
15
  Welcome to the **Duel Agent Simulation** app! This Streamlit application allows you to chat with Meta's Llama3 model in a unique interview simulation. The app features two agents in an interview scenario, with a judge providing feedback. The best part? You simply provide a topic, and the simulation runs itself!
 
16
  ## Features
 
17
  ### πŸ“ Instruction Manual
 
18
  **Meta Llama3 πŸ¦™ Chatbot**
 
19
  This application lets you interact with Meta's Llama3 model through a fun interview-style chat.
 
20
  **How to Use:**
21
  1. **Input:** Type a topic into the input box labeled "Enter a topic".
22
+ 2. **Submit:** Press the "Run Simulation!" button to start the simulation.
23
  3. **Chat History:** View the previous conversations as the simulation unfolds.
 
24
  **Credits:**
25
  - **Developer:** Kethan Dosapati
26
  - [LinkedIn](https://www.linkedin.com/in/kethan-dosapati/)
 
35
  # Add a button to clear the session state
36
  if st.button("Clear Session"):
37
  st.session_state.messages = []
38
+ st.session_state.simulation_data = []
39
  st.experimental_rerun()
40
 
41
  # Initialize chat history
42
  if "messages" not in st.session_state:
43
  st.session_state.messages = []
44
+
45
+ # Initialize simulation data storage
46
+ if "simulation_data" not in st.session_state:
47
+ st.session_state.simulation_data = {
48
+ "iterations": [],
49
+ "questions": [],
50
+ "answers": [],
51
+ "judge_comments": [],
52
+ "passes": []
53
+ }
54
 
55
  # Display chat messages from history on app rerun
56
  for message in st.session_state.messages:
 
63
  judge = call_llama
64
 
65
  # React to user input
 
 
 
 
 
 
66
  if submit_button:
67
+ iter = 0
 
68
  prompt = f"Ask a question about this topic: {user_topic}"
69
 
70
  # Display user message in chat message container
71
+ st.chat_message("user").markdown(f"Topic: {user_topic}")
72
+ st.session_state.messages.append({"role": "user", "content": f"Topic: {user_topic}"})
73
+
74
+ with st.spinner("Running simulation..."):
75
+ while True:
76
+ # Interviewer asks a question
77
+ question = interviewer(prompt)
78
+
79
+ # Display question
80
+ st.chat_message("assistant").markdown(question)
81
+ st.session_state.messages.append({"role": "assistant", "content": question})
82
+
83
+ # Interviewee answers
84
+ if iter < 2: # First few answers are mediocre
85
+ answer_prompt = f"Answer the question: {question} in a mediocre way because you are an inexperienced interviewee."
86
+ else: # Later answers try to improve
87
+ judge_comments = st.session_state.simulation_data["judge_comments"][-1] if iter > 0 else ""
88
+ answer_prompt = f"""Answer the question: {question} in a mediocre way because you are an inexperienced interviewee,
89
+ but you're learning from these judge comments: {judge_comments}"""
90
+
91
+ answer = interviewee(answer_prompt)
 
 
 
 
 
 
 
 
 
 
92
  st.chat_message("user").markdown(answer)
93
  st.session_state.messages.append({"role": "user", "content": answer})
94
 
95
+ # Judge evaluates
96
+ judge_prompt = f"""The question was: {question}
97
+ The answer was: {answer}
98
+ Provide brief feedback and rate the answer from 1 to 10 (10 being best)."""
99
+ judge_comments = judge(judge_prompt)
100
+
101
+ # Store results
102
+ passed = 1 if any(str(i) in judge_comments for i in [8, 9, 10]) else 0
103
+ st.session_state.simulation_data["iterations"].append(iter)
104
+ st.session_state.simulation_data["questions"].append(question)
105
+ st.session_state.simulation_data["answers"].append(answer)
106
+ st.session_state.simulation_data["judge_comments"].append(judge_comments)
107
+ st.session_state.simulation_data["passes"].append(passed)
108
+
109
+ # Show results table
110
+ with st.expander("Simulation Details"):
111
+ results_df = pd.DataFrame({
112
+ "Iteration": st.session_state.simulation_data["iterations"],
113
+ "Question": st.session_state.simulation_data["questions"],
114
+ "Answer": st.session_state.simulation_data["answers"],
115
+ "Judge Feedback": st.session_state.simulation_data["judge_comments"],
116
+ "Passed?": ["βœ…" if x else "❌" for x in st.session_state.simulation_data["passes"]]
117
+ })
118
+ st.table(results_df)
119
+
120
+ # Stopping condition
121
+ if passed:
122
+ st.success("Interview passed! The candidate gave a good enough answer.")
123
+ break
124
+
125
+ if iter >= 5: # Max iterations
126
+ st.warning("Interview ended - maximum attempts reached")
127
+ break
128
+
129
+ iter += 1
130
+ prompt = f"Ask another follow-up question about: {user_topic}"