CoolFace
Apppublic

DKethan/Duel-Simulation

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
app.py150 linesDownload Raw Back to root
1import streamlit as st2import os3import pandas as pd4from together import Together5from helper import *6 7 8st.set_page_config(layout="wide")9st.title("Duel Agent Simulation ๐Ÿฆ™๐Ÿฆ™")10 11 12with st.sidebar:13    with st.expander("Instruction Manual"):14        st.markdown("""15            # ๐Ÿฆ™๐Ÿฆ™ Duel Agent Simulation Streamlit App16            17            ## Overview18            19            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!20            21            ## Features22            23            ### ๐Ÿ“ Instruction Manual24            25            **Meta Llama3 ๐Ÿฆ™ Chatbot**26            27            This application lets you interact with Meta's Llama3 model through a fun interview-style chat.28            29            **How to Use:**30            1. **Input:** Type a topic into the input box labeled "Enter a topic".31            2. **Submit:** Press the "Submit" button to start the simulation.32            3. **Chat History:** View the previous conversations as the simulation unfolds.33            34            **Credits:**35            - **Developer:** Yiqiao Yin  36               - [Site](https://www.y-yin.io/)  37               - [LinkedIn](https://www.linkedin.com/in/yiqiaoyin/)  38               - [YouTube](https://youtube.com/YiqiaoYin/)  39        """)40 41    # Text input42    user_topic = st.text_input("Enter a topic", "Data Science")43 44    # Add a button to submit45    submit_button = st.button("Run Simulation!")46 47    # Add a button to clear the session state48    if st.button("Clear Session"):49        st.session_state.messages = []50        st.experimental_rerun()51 52 53# Initialize chat history54if "messages" not in st.session_state:55    st.session_state.messages = []56 57 58# Display chat messages from history on app rerun59for message in st.session_state.messages:60    with st.chat_message(message["role"]):61        st.markdown(message["content"])62 63 64# Create agents65interviewer = call_llama66interviewee = call_llama67judge = call_llama68 69 70# React to user input71iter = 072list_of_iters = []73list_of_questions = []74list_of_answers = []75list_of_judge_comments = []76list_of_passes = []77if submit_button:78 79    # Initiatization80    prompt = f"Ask a question about this topic: {user_topic}"81 82    # Display user message in chat message container83    # Default: user=interviewee, assistant=interviewer84    st.chat_message("user").markdown(prompt)85    st.session_state.messages.append({"role": "user", "content": prompt})86 87    while True:88 89        # Interview asks a question90        question = interviewer(prompt)91 92        # Display assistant response in chat message container93        st.chat_message("assistant").markdown(question)94        st.session_state.messages.append({"role": "assistant", "content": question})95 96        # Interviewee attempts an answer97        if iter < 5:98            answer = interviewee(99                f"""100                    Answer the question: {question} in a mediocre way101                    Because you are an inexperienced interviewee.102                """103            )104            st.chat_message("user").markdown(answer)105            st.session_state.messages.append({"role": "user", "content": answer})106        else:107            answer = interviewee(108                f"""109                    Answer the question: {question} in a mediocre way110                    Because you are an inexperienced interviewee but you really want to learn,111                    so you learn from the judge comments: {judge_comments}112                """113            )114            st.chat_message("user").markdown(answer)115            st.session_state.messages.append({"role": "user", "content": answer})116 117        # Judge thinks and advises but the thoughts are hidden118        judge_comments = judge(119            f"""120                The question is: {question}121                The answer is: {answer}122                Provide feedback and rate the answer from 1 to 10 while 10 being the best and 1 is the worst. 123            """124        )125        126 127        # Collect all responses128        passed_or_not = 1 if '8' in judge_comments else 0129        list_of_iters.append(iter)130        list_of_questions.append(question)131        list_of_answers.append(answer)132        list_of_judge_comments.append(judge_comments)133        list_of_passes.append(passed_or_not)134        results_tab = pd.DataFrame({135            "Iter.": list_of_iters,136            "Questions": list_of_questions,137            "Answers": list_of_answers,138            "Judge Comments": list_of_judge_comments,139            "Passed": list_of_passes140        })141 142        with st.expander("See explanation"):143            st.table(results_tab)144 145        # Stopping rule146        if '8' in judge_comments:147            break148 149        # Checkpoint150        iter += 1