Aditya-1911's picture
Update app.py
5cff1ec verified
import streamlit as st
import os
import pandas as pd
from together import Together
from helper import *
# Set page config with a favicon
st.set_page_config(
page_title="Duel Agent Simulator",
layout="wide")
# Custom CSS for premium styling and animations
st.markdown("""
<style>
body {
background-color: #0d0d0d;
color: white;
}
.big-title {
font-size: 48px !important;
font-weight: bold;
text-align: center;
color: #D4AF37;
animation: fadeIn 1.5s;
text-shadow: 2px 2px 12px rgba(212, 175, 55, 0.7);
}
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
.stButton>button {
background: linear-gradient(135deg, #D4AF37, #8B7500) !important;
color: white !important;
font-size: 20px;
font-weight: bold;
border-radius: 15px;
padding: 14px;
transition: transform 0.2s, box-shadow 0.2s;
}
.stButton>button:hover {
transform: scale(1.08);
box-shadow: 0px 0px 15px rgba(212, 175, 55, 0.8);
}
.stTextInput>div>div>input {
border-radius: 15px;
border: 2px solid #D4AF37;
padding: 12px;
background-color: #222;
color: white;
font-size: 16px;
}
.sidebar .sidebar-content {
background-color: #1a1a1a;
border-right: 3px solid #D4AF37;
}
</style>
""", unsafe_allow_html=True)
# Title with animation
st.markdown("<p class='big-title'>⚑ Duel Agent Simulator ⚑</p>", unsafe_allow_html=True)
# Sidebar - Instruction Manual
with st.sidebar:
st.image("favicon.ico", width=48)
with st.expander("πŸ“– Instruction Manual"):
st.markdown("""
## ⚑ Duel Agent Simulator Guide
- Input a **topic** below.
- Click **Run Simulation!** to generate the interview.
- See the **conversation** unfold live!
**Tip:** Each interaction gets better as the agent learns!
""")
user_topic = st.text_input("Enter a topic", "Data Science")
col1, col2 = st.columns(2)
with col1:
submit_button = st.button("πŸš€ Start Simulation!")
with col2:
if st.button("πŸ” Reset Session"):
st.session_state.messages = []
st.rerun()
# Initialize chat history
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat messages
for message in st.session_state.messages:
with st.chat_message(message["role"]):
st.markdown(message["content"])
# Create Agents
interviewer, interviewee, judge, humorist, stats_guru = call_gemini, call_gemini, call_gemini, call_gemini, call_gemini
# Lists to store results
iter, list_of_iters, list_of_questions, list_of_answers, list_of_judge_comments, list_of_passes, list_of_jokes, list_of_stats = 0, [], [], [], [], [], [], []
if submit_button:
st.chat_message("user").markdown(f"**User Topic:** {user_topic}")
st.session_state.messages.append({"role": "user", "content": user_topic})
while True:
question = interviewer(f"Ask a question about this topic: {user_topic}")
with st.spinner("πŸ€– Interviewer thinking..."):
st.chat_message("assistant").markdown(f"**Interviewer:** {question}")
st.session_state.messages.append({"role": "assistant", "content": question})
if iter < 5:
answer = interviewee(f"Answer the question: {question} in a mediocre way as an inexperienced interviewee.")
else:
answer = interviewee(f"Answer the question: {question}, learning from the judge's feedback: {judge_comments}")
st.chat_message("user").markdown(f"**Interviewee:** {answer}")
st.session_state.messages.append({"role": "user", "content": answer})
judge_comments = judge(f"Evaluate: {question}\nAnswer: {answer}\nRate 1-10 and provide feedback.")
st.success(f"πŸ§‘β€βš–οΈ Judge: {judge_comments}")
joke = humorist(f"Make a joke about the interviewee's answer: {answer}")
st.warning(f"🎭 **Humorist:** {joke}")
st.session_state.messages.append({"role": "assistant", "content": joke})
stats_comment = stats_guru(f"Give an interesting statistical insight or fact based on this topic: {user_topic}")
st.info(f"πŸ“Š **Statistics Guru:** {stats_comment}")
st.session_state.messages.append({"role": "assistant", "content": stats_comment})
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_jokes.append(joke)
list_of_stats.append(stats_comment)
list_of_passes.append(passed_or_not)
with st.expander("πŸ“Š Simulation Summary"):
st.table(pd.DataFrame({
"Iteration": list_of_iters,
"Questions": list_of_questions,
"Answers": list_of_answers,
"Judge Feedback": list_of_judge_comments,
"Jokes": list_of_jokes,
"Stats": list_of_stats,
"Passed": list_of_passes
}))
if '8' in judge_comments:
break
iter += 1