CoolFace
Apppublic

samadarshini/dual-agent-simulation

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py152 linesDownload Raw Back to root
1 2import streamlit as st3import os4import pandas as pd5from together import Together6from utils.helper import *7 8 9st.set_page_config(layout="wide")10st.title("Duel Agent Simulation ๐Ÿฆ™๐Ÿฆ™")11 12 13with st.sidebar:14    with st.expander("Instruction Manual"):15        st.markdown("""16            # ๐Ÿฆ™๐Ÿฆ™ Duel Agent Simulation Streamlit App17            18            ## Overview19            20            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!21            22            ## Features23            24            ### ๐Ÿ“ Instruction Manual25            26            **Meta Llama3 ๐Ÿฆ™ Chatbot**27            28            This application lets you interact with Meta's Llama3 model through a fun interview-style chat.29            30            **How to Use:**31            1. **Input:** Type a topic into the input box labeled "Enter a topic".32            2. **Submit:** Press the "Submit" button to start the simulation.33            3. **Chat History:** View the previous conversations as the simulation unfolds.34            35            **Credits:**36            - **Developer:** Yiqiao Yin  37               - [Site](https://www.y-yin.io/)  38               - [LinkedIn](https://www.linkedin.com/in/yiqiaoyin/)  39               - [YouTube](https://youtube.com/YiqiaoYin/)  40        """)41 42    # Text input43    user_topic = st.text_input("Enter a topic", "Data Science")44 45    # Add a button to submit46    submit_button = st.button("Run Simulation!")47 48    # Add a button to clear the session state49    if st.button("Clear Session"):50        st.session_state.messages = []51        st.experimental_rerun()52 53 54# Initialize chat history55if "messages" not in st.session_state:56    st.session_state.messages = []57 58 59# Display chat messages from history on app rerun60for message in st.session_state.messages:61    with st.chat_message(message["role"]):62        st.markdown(message["content"])63 64 65# Create agents66interviewer = call_llama67interviewee = call_llama68judge = call_llama69 70 71# React to user input72iter = 073list_of_iters = []74list_of_questions = []75list_of_answers = []76list_of_judge_comments = []77list_of_passes = []78if submit_button:79 80    # Initiatization81    prompt = f"Ask a question about this topic: {user_topic}"82 83    # Display user message in chat message container84    # Default: user=interviewee, assistant=interviewer85    st.chat_message("user").markdown(prompt)86    st.session_state.messages.append({"role": "user", "content": prompt})87 88    while True:89 90        # Interview asks a question91        question = interviewer(prompt)92 93        # Display assistant response in chat message container94        st.chat_message("assistant").markdown(question)95        st.session_state.messages.append({"role": "assistant", "content": question})96 97        # Interviewee attempts an answer98        if iter < 5:99            answer = interviewee(100                f"""101                    Answer the question: {question} in a mediocre way102                    Because you are an inexperienced interviewee.103                """104            )105            st.chat_message("user").markdown(answer)106            st.session_state.messages.append({"role": "user", "content": answer})107        else:108            answer = interviewee(109                f"""110                    Answer the question: {question} in a mediocre way111                    Because you are an inexperienced interviewee but you really want to learn,112                    so you learn from the judge comments: {judge_comments}113                """114            )115            st.chat_message("user").markdown(answer)116            st.session_state.messages.append({"role": "user", "content": answer})117 118        # Judge thinks and advises but the thoughts are hidden119        judge_comments = judge(120            f"""121                The question is: {question}122                The answer is: {answer}123                Provide feedback and rate the answer from 1 to 10 while 10 being the best and 1 is the worst. 124            """125        )126        127 128        # Collect all responses129        passed_or_not = 1 if '8' in judge_comments else 0130        list_of_iters.append(iter)131        list_of_questions.append(question)132        list_of_answers.append(answer)133        list_of_judge_comments.append(judge_comments)134        list_of_passes.append(passed_or_not)135        results_tab = pd.DataFrame({136            "Iter.": list_of_iters,137            "Questions": list_of_questions,138            "Answers": list_of_answers,139            "Judge Comments": list_of_judge_comments,140            "Passed": list_of_passes141        })142 143        with st.expander("See explanation"):144            st.table(results_tab)145 146        # Stopping rule147        if '8' in judge_comments:148            break149 150        # Checkpoint151        iter += 1152