Spaces:
Sleeping
Sleeping
File size: 6,459 Bytes
61032a4 0bd18d4 61032a4 0bd18d4 61032a4 0bd18d4 61032a4 0bd18d4 11a689c 61032a4 0bd18d4 61032a4 0bd18d4 61032a4 0bd18d4 61032a4 0bd18d4 61032a4 0bd18d4 |
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 154 155 156 157 158 159 160 161 162 163 164 |
import streamlit as st
import openai
import google.generativeai as genai
# Custom CSS for arena styling
st.markdown("""
<style>
.fighter-column {
border: 2px solid #4a4a4a;
border-radius: 10px;
padding: 20px;
margin: 10px;
background: #1a1a1a;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
}
.vote-btn {
width: 100%;
margin-top: 10px;
}
.arena-title {
text-align: center;
font-size: 2.5em !important;
color: #ffd700 !important;
margin-bottom: 20px !important;
}
</style>
""", unsafe_allow_html=True)
def get_openai_response(api_key, model, prompt):
client = openai.OpenAI(api_key=api_key)
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
def get_gemini_response(api_key, model, prompt):
genai.configure(api_key=api_key)
model = genai.GenerativeModel(model)
response = model.generate_content(prompt)
return response.text
def get_deepseek_response(api_key, model, prompt):
client = openai.OpenAI(
api_key=api_key,
base_url="https://api.deepseek.com/v1",
)
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content
# Initialize session state for voting
if 'votes' not in st.session_state:
st.session_state.votes = {'OpenAI': 0, 'Gemini': 0, 'DeepSeek': 0}
# Sidebar configuration
with st.sidebar:
st.header("βοΈ Battle Configuration")
st.subheader("API Keys")
openai_api_key = st.text_input("OpenAI Key", type="password")
gemini_api_key = st.text_input("Gemini Key", type="password")
deepseek_api_key = st.text_input("DeepSeek Key", type="password")
st.subheader("Model Selection")
openai_model = st.text_input("OpenAI Model", value="o1-mini")
gemini_model = st.text_input("Gemini Model", value="gemini-2.0-flash-exp")
deepseek_model = st.text_input("DeepSeek Model", value="deepseek-reasoner")
# Main Arena
st.markdown('<p class="arena-title">π€ LLM BATTLE ARENA π₯</p>', unsafe_allow_html=True)
prompt = st.text_area("Enter your battle prompt:", height=150, help="The prompt that will determine the AI champion!")
if st.button("π Start Battle!"):
if not prompt.strip():
st.error("Please enter a battle prompt!")
else:
responses = {}
# Get all responses
with st.spinner("βοΈ Models are battling it out..."):
col1, col2, col3 = st.columns(3)
# OpenAI Fighter
with col1:
with st.container():
st.markdown('<div class="fighter-column">', unsafe_allow_html=True)
st.markdown("### π₯ OpenAI\n`" + openai_model + "`")
try:
if openai_api_key:
response = get_openai_response(openai_api_key, openai_model, prompt)
responses["OpenAI"] = response
st.markdown("---")
st.write(response)
else:
st.error("Missing API Key!")
except Exception as e:
st.error(f"Battle error: {str(e)}")
st.markdown('</div>', unsafe_allow_html=True)
# Gemini Fighter
with col2:
with st.container():
st.markdown('<div class="fighter-column">', unsafe_allow_html=True)
st.markdown("### π₯ Gemini\n`" + gemini_model + "`")
try:
if gemini_api_key:
response = get_gemini_response(gemini_api_key, gemini_model, prompt)
responses["Gemini"] = response
st.markdown("---")
st.write(response)
else:
st.error("Missing API Key!")
except Exception as e:
st.error(f"Battle error: {str(e)}")
st.markdown('</div>', unsafe_allow_html=True)
# DeepSeek Fighter
with col3:
with st.container():
st.markdown('<div class="fighter-column">', unsafe_allow_html=True)
st.markdown("### π₯ DeepSeek\n`" + deepseek_model + "`")
try:
if deepseek_api_key:
response = get_deepseek_response(deepseek_api_key, deepseek_model, prompt)
responses["DeepSeek"] = response
st.markdown("---")
st.write(response)
else:
st.error("Missing API Key!")
except Exception as e:
st.error(f"Battle error: {str(e)}")
st.markdown('</div>', unsafe_allow_html=True)
# Voting Section
st.markdown("---")
st.subheader("π Judge the Responses!")
cols = st.columns(3)
with cols[0]:
if st.button("Vote OpenAI π", key="vote_openai"):
st.session_state.votes["OpenAI"] += 1
with cols[1]:
if st.button("Vote Gemini π", key="vote_gemini"):
st.session_state.votes["Gemini"] += 1
with cols[2]:
if st.button("Vote DeepSeek π", key="vote_deepseek"):
st.session_state.votes["DeepSeek"] += 1
# Leaderboard
st.markdown("---")
st.subheader("π Battle Leaderboard")
sorted_votes = sorted(st.session_state.votes.items(), key=lambda x: x[1], reverse=True)
for i, (model, votes) in enumerate(sorted_votes):
trophy = "π₯" if i == 0 else "π₯" if i == 1 else "π₯"
st.markdown(f"{trophy} **{model}**: {votes} votes")
st.progress(votes / (sum(st.session_state.votes.values()) or 1))
# How to Run reminder in sidebar
with st.sidebar:
st.markdown("---")
st.markdown("**How to start the battle:**")
st.markdown("1. Enter API keys π\n2. Set models π§ \n3. Write prompt π\n4. Click battle button! βοΈ") |