DronA23 commited on
Commit
409647f
Β·
verified Β·
1 Parent(s): 006ff61

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +142 -0
app.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ 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 πŸ¦™πŸ¦™")
10
+
11
+ 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/)
36
+ """)
37
+
38
+ # Text input
39
+ user_topic = st.text_input("Enter a topic", "Data Science")
40
+
41
+ # Add a button to submit
42
+ submit_button = st.button("Run Simulation!")
43
+
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:
55
+ with st.chat_message(message["role"]):
56
+ st.markdown(message["content"])
57
+
58
+ # Create agents
59
+ interviewer = call_llama
60
+ 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