Spaces:
Sleeping
Sleeping
File size: 4,913 Bytes
160a98a e0e7881 2ad5826 e0e7881 f600ca3 160a98a 310f00a 160a98a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
import streamlit as st
import os
import pandas as pd
from utils.helper import *
os.system("pip install together")
os.system("python3 -m pip install --no-cache-dir together")
from together import Together
st.set_page_config(layout="wide")
st.title("Dual Agent ChatBot ๐ค")
with st.sidebar:
with st.expander("Instruction Manual"):
st.markdown("""
# Duel Agent ChatBot Streamlit App
## Overview
Welcome to the **Duel Agent ChatBot** 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!
## Features
### ๐ Instruction Manual
**Meta Llama3 ๐ฆ Chatbot**
This application lets you interact with Meta's Llama3 model through a fun interview-style chat.
**How to Use:**
1. **Input:** Type a topic into the input box labeled "Enter a topic".
2. **Submit:** Press the "Submit" button to start the simulation.
3. **Chat History:** View the previous conversations as the simulation unfolds.
**Credits:**
- **Developer:** Ali Inamdar
""")
# Text input
user_topic = st.text_input("Enter a topic", "Data Science")
# Add a button to submit
submit_button = st.button("Run Simulation!")
# Add a button to clear the session state
if st.button("Clear Session"):
st.session_state.messages = []
st.experimental_rerun()
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages from history on app rerun
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Create agents
interviewer = call_llama
interviewee = call_llama
judge = call_llama
# React to user input
iter = 0
list_of_iters = []
list_of_questions = []
list_of_answers = []
list_of_judge_comments = []
list_of_passes = []
if submit_button:
# Initiatization
prompt = f"Ask a question about this topic: {user_topic}"
# Display user message in chat message container
# Default: user=interviewee, assistant=interviewer
st.chat_message("user").markdown(prompt)
st.session_state.messages.append({"role": "user", "content": prompt})
while True:
# Interview asks a question
question = interviewer(prompt)
# Display assistant response in chat message container
st.chat_message("assistant").markdown(question)
st.session_state.messages.append({"role": "assistant", "content": question})
# Interviewee attempts an answer
if iter < 5:
answer = interviewee(
f"""
Answer the question: {question} in a mediocre way
Because you are an inexperienced interviewee.
"""
)
st.chat_message("user").markdown(answer)
st.session_state.messages.append({"role": "user", "content": answer})
else:
answer = interviewee(
f"""
Answer the question: {question} in a mediocre way
Because you are an inexperienced interviewee but you really want to learn,
so you learn from the judge comments: {judge_comments}
"""
)
st.chat_message("user").markdown(answer)
st.session_state.messages.append({"role": "user", "content": answer})
# Judge thinks and advises but the thoughts are hidden
judge_comments = judge(
f"""
The question is: {question}
The answer is: {answer}
Provide feedback and rate the answer from 1 to 10 while 10 being the best and 1 is the worst.
"""
)
# Collect all responses
passed_or_not = 1 if '8' in judge_comments else 0
list_of_iters.append(iter)
list_of_questions.append(question)
list_of_answers.append(answer)
list_of_judge_comments.append(judge_comments)
list_of_passes.append(passed_or_not)
results_tab = pd.DataFrame({
"Iter.": list_of_iters,
"Questions": list_of_questions,
"Answers": list_of_answers,
"Judge Comments": list_of_judge_comments,
"Passed": list_of_passes
})
with st.expander("See explanation"):
st.table(results_tab)
# Stopping rule
if '8' in judge_comments:
break
# Checkpoint
iter += 1 |