Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,30 @@ import streamlit as st
|
|
| 2 |
import openai
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
def get_openai_response(api_key, model, prompt):
|
| 6 |
client = openai.OpenAI(api_key=api_key)
|
| 7 |
response = client.chat.completions.create(
|
|
@@ -27,72 +51,114 @@ def get_deepseek_response(api_key, model, prompt):
|
|
| 27 |
)
|
| 28 |
return response.choices[0].message.content
|
| 29 |
|
| 30 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
with st.sidebar:
|
| 32 |
-
st.header("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
openai_api_key = st.text_input("OpenAI API Key", type="password")
|
| 36 |
openai_model = st.text_input("OpenAI Model", value="o1-mini")
|
| 37 |
-
|
| 38 |
-
# Gemini
|
| 39 |
-
gemini_api_key = st.text_input("Gemini API Key", type="password")
|
| 40 |
gemini_model = st.text_input("Gemini Model", value="gemini-2.0-flash-exp")
|
| 41 |
-
|
| 42 |
-
# DeepSeek
|
| 43 |
-
deepseek_api_key = st.text_input("DeepSeek API Key", type="password")
|
| 44 |
deepseek_model = st.text_input("DeepSeek Model", value="deepseek-reasoner")
|
| 45 |
|
| 46 |
-
# Main
|
| 47 |
-
st.
|
| 48 |
-
prompt = st.text_area("Enter your prompt:", height=150)
|
| 49 |
-
submit_button = st.button("Submit")
|
| 50 |
|
| 51 |
-
if
|
| 52 |
if not prompt.strip():
|
| 53 |
-
st.error("Please enter a prompt
|
| 54 |
else:
|
| 55 |
responses = {}
|
| 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 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import openai
|
| 3 |
import google.generativeai as genai
|
| 4 |
|
| 5 |
+
# Custom CSS for arena styling
|
| 6 |
+
st.markdown("""
|
| 7 |
+
<style>
|
| 8 |
+
.fighter-column {
|
| 9 |
+
border: 2px solid #4a4a4a;
|
| 10 |
+
border-radius: 10px;
|
| 11 |
+
padding: 20px;
|
| 12 |
+
margin: 10px;
|
| 13 |
+
background: #1a1a1a;
|
| 14 |
+
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
|
| 15 |
+
}
|
| 16 |
+
.vote-btn {
|
| 17 |
+
width: 100%;
|
| 18 |
+
margin-top: 10px;
|
| 19 |
+
}
|
| 20 |
+
.arena-title {
|
| 21 |
+
text-align: center;
|
| 22 |
+
font-size: 2.5em !important;
|
| 23 |
+
color: #ffd700 !important;
|
| 24 |
+
margin-bottom: 20px !important;
|
| 25 |
+
}
|
| 26 |
+
</style>
|
| 27 |
+
""", unsafe_allow_html=True)
|
| 28 |
+
|
| 29 |
def get_openai_response(api_key, model, prompt):
|
| 30 |
client = openai.OpenAI(api_key=api_key)
|
| 31 |
response = client.chat.completions.create(
|
|
|
|
| 51 |
)
|
| 52 |
return response.choices[0].message.content
|
| 53 |
|
| 54 |
+
# Initialize session state for voting
|
| 55 |
+
if 'votes' not in st.session_state:
|
| 56 |
+
st.session_state.votes = {'OpenAI': 0, 'Gemini': 0, 'DeepSeek': 0}
|
| 57 |
+
|
| 58 |
+
# Sidebar configuration
|
| 59 |
with st.sidebar:
|
| 60 |
+
st.header("βοΈ Battle Configuration")
|
| 61 |
+
st.subheader("API Keys")
|
| 62 |
+
openai_api_key = st.text_input("OpenAI Key", type="password")
|
| 63 |
+
gemini_api_key = st.text_input("Gemini Key", type="password")
|
| 64 |
+
deepseek_api_key = st.text_input("DeepSeek Key", type="password")
|
| 65 |
|
| 66 |
+
st.subheader("Model Selection")
|
|
|
|
| 67 |
openai_model = st.text_input("OpenAI Model", value="o1-mini")
|
|
|
|
|
|
|
|
|
|
| 68 |
gemini_model = st.text_input("Gemini Model", value="gemini-2.0-flash-exp")
|
|
|
|
|
|
|
|
|
|
| 69 |
deepseek_model = st.text_input("DeepSeek Model", value="deepseek-reasoner")
|
| 70 |
|
| 71 |
+
# Main Arena
|
| 72 |
+
st.markdown('<p class="arena-title">π€ LLM BATTLE ARENA π₯</p>', unsafe_allow_html=True)
|
| 73 |
+
prompt = st.text_area("Enter your battle prompt:", height=150, help="The prompt that will determine the AI champion!")
|
|
|
|
| 74 |
|
| 75 |
+
if st.button("π Start Battle!"):
|
| 76 |
if not prompt.strip():
|
| 77 |
+
st.error("Please enter a battle prompt!")
|
| 78 |
else:
|
| 79 |
responses = {}
|
| 80 |
|
| 81 |
+
# Get all responses
|
| 82 |
+
with st.spinner("βοΈ Models are battling it out..."):
|
| 83 |
+
col1, col2, col3 = st.columns(3)
|
| 84 |
+
|
| 85 |
+
# OpenAI Fighter
|
| 86 |
+
with col1:
|
| 87 |
+
with st.container():
|
| 88 |
+
st.markdown('<div class="fighter-column">', unsafe_allow_html=True)
|
| 89 |
+
st.markdown("### π₯ OpenAI\n`" + openai_model + "`")
|
| 90 |
+
try:
|
| 91 |
+
if openai_api_key:
|
| 92 |
+
response = get_openai_response(openai_api_key, openai_model, prompt)
|
| 93 |
+
responses["OpenAI"] = response
|
| 94 |
+
st.markdown("---")
|
| 95 |
+
st.write(response)
|
| 96 |
+
else:
|
| 97 |
+
st.error("Missing API Key!")
|
| 98 |
+
except Exception as e:
|
| 99 |
+
st.error(f"Battle error: {str(e)}")
|
| 100 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 101 |
+
|
| 102 |
+
# Gemini Fighter
|
| 103 |
+
with col2:
|
| 104 |
+
with st.container():
|
| 105 |
+
st.markdown('<div class="fighter-column">', unsafe_allow_html=True)
|
| 106 |
+
st.markdown("### π₯ Gemini\n`" + gemini_model + "`")
|
| 107 |
+
try:
|
| 108 |
+
if gemini_api_key:
|
| 109 |
+
response = get_gemini_response(gemini_api_key, gemini_model, prompt)
|
| 110 |
+
responses["Gemini"] = response
|
| 111 |
+
st.markdown("---")
|
| 112 |
+
st.write(response)
|
| 113 |
+
else:
|
| 114 |
+
st.error("Missing API Key!")
|
| 115 |
+
except Exception as e:
|
| 116 |
+
st.error(f"Battle error: {str(e)}")
|
| 117 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 118 |
+
|
| 119 |
+
# DeepSeek Fighter
|
| 120 |
+
with col3:
|
| 121 |
+
with st.container():
|
| 122 |
+
st.markdown('<div class="fighter-column">', unsafe_allow_html=True)
|
| 123 |
+
st.markdown("### π₯ DeepSeek\n`" + deepseek_model + "`")
|
| 124 |
+
try:
|
| 125 |
+
if deepseek_api_key:
|
| 126 |
+
response = get_deepseek_response(deepseek_api_key, deepseek_model, prompt)
|
| 127 |
+
responses["DeepSeek"] = response
|
| 128 |
+
st.markdown("---")
|
| 129 |
+
st.write(response)
|
| 130 |
+
else:
|
| 131 |
+
st.error("Missing API Key!")
|
| 132 |
+
except Exception as e:
|
| 133 |
+
st.error(f"Battle error: {str(e)}")
|
| 134 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
| 135 |
+
|
| 136 |
+
# Voting Section
|
| 137 |
+
st.markdown("---")
|
| 138 |
+
st.subheader("π Judge the Responses!")
|
| 139 |
+
cols = st.columns(3)
|
| 140 |
+
with cols[0]:
|
| 141 |
+
if st.button("Vote OpenAI π", key="vote_openai"):
|
| 142 |
+
st.session_state.votes["OpenAI"] += 1
|
| 143 |
+
with cols[1]:
|
| 144 |
+
if st.button("Vote Gemini π", key="vote_gemini"):
|
| 145 |
+
st.session_state.votes["Gemini"] += 1
|
| 146 |
+
with cols[2]:
|
| 147 |
+
if st.button("Vote DeepSeek π", key="vote_deepseek"):
|
| 148 |
+
st.session_state.votes["DeepSeek"] += 1
|
| 149 |
+
|
| 150 |
+
# Leaderboard
|
| 151 |
+
st.markdown("---")
|
| 152 |
+
st.subheader("π Battle Leaderboard")
|
| 153 |
+
sorted_votes = sorted(st.session_state.votes.items(), key=lambda x: x[1], reverse=True)
|
| 154 |
|
| 155 |
+
for i, (model, votes) in enumerate(sorted_votes):
|
| 156 |
+
trophy = "π₯" if i == 0 else "π₯" if i == 1 else "π₯"
|
| 157 |
+
st.markdown(f"{trophy} **{model}**: {votes} votes")
|
| 158 |
+
st.progress(votes / (sum(st.session_state.votes.values()) or 1))
|
| 159 |
+
|
| 160 |
+
# How to Run reminder in sidebar
|
| 161 |
+
with st.sidebar:
|
| 162 |
+
st.markdown("---")
|
| 163 |
+
st.markdown("**How to start the battle:**")
|
| 164 |
+
st.markdown("1. Enter API keys π\n2. Set models π§ \n3. Write prompt π\n4. Click battle button! βοΈ")
|