|
import streamlit as st |
|
import time |
|
import requests |
|
from streamlit.components.v1 import html |
|
import os |
|
|
|
|
|
@st.cache_resource |
|
def get_help_agent(): |
|
from transformers import pipeline |
|
|
|
return pipeline("conversational", model="facebook/blenderbot-400M-distill") |
|
|
|
|
|
def inject_custom_css(): |
|
st.markdown(""" |
|
<style> |
|
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap'); |
|
|
|
* { |
|
font-family: 'Inter', sans-serif; |
|
margin: 0; |
|
padding: 0; |
|
box-sizing: border-box; |
|
} |
|
|
|
.title { |
|
font-size: 2.8rem !important; |
|
font-weight: 800 !important; |
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
|
-webkit-background-clip: text; |
|
-webkit-text-fill-color: transparent; |
|
text-align: center; |
|
margin: 1rem 0; |
|
letter-spacing: -1px; |
|
} |
|
|
|
.subtitle { |
|
font-size: 1.1rem !important; |
|
text-align: center; |
|
color: #4a5568 !important; |
|
margin-bottom: 2.5rem; |
|
font-weight: 500; |
|
} |
|
|
|
.question-container { |
|
background: #f7fafc; |
|
border-radius: 20px; |
|
padding: 2rem; |
|
margin: 1.5rem 0; |
|
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); |
|
position: relative; |
|
border: 1px solid #e2e8f0; |
|
} |
|
|
|
.question-container::after { |
|
content: ''; |
|
position: absolute; |
|
bottom: -10px; |
|
left: 40px; |
|
width: 0; |
|
height: 0; |
|
border-left: 12px solid transparent; |
|
border-right: 12px solid transparent; |
|
border-top: 12px solid #f7fafc; |
|
} |
|
|
|
.question-text { |
|
font-size: 1.25rem !important; |
|
color: #2d3748 !important; |
|
line-height: 1.6; |
|
margin-bottom: 0; |
|
} |
|
|
|
.input-box { |
|
background: white !important; |
|
border-radius: 12px !important; |
|
border: 2px solid #e2e8f0 !important; |
|
padding: 0.75rem 1rem !important; |
|
font-size: 1rem !important; |
|
transition: all 0.3s ease !important; |
|
} |
|
|
|
.input-box:focus { |
|
border-color: #667eea !important; |
|
box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.2) !important; |
|
} |
|
|
|
.submit-btn { |
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; |
|
color: white !important; |
|
border: none !important; |
|
padding: 0.75rem 2rem !important; |
|
border-radius: 10px !important; |
|
font-weight: 600 !important; |
|
transition: transform 0.2s ease !important; |
|
} |
|
|
|
.submit-btn:hover { |
|
transform: translateY(-2px); |
|
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.3) !important; |
|
} |
|
|
|
.progress-bar { |
|
height: 8px; |
|
background: #e2e8f0; |
|
border-radius: 4px; |
|
margin: 1.5rem 0; |
|
overflow: hidden; |
|
} |
|
|
|
.progress-fill { |
|
height: 100%; |
|
background: linear-gradient(90deg, #667eea 0%, #764ba2 100%); |
|
transition: width 0.3s ease; |
|
} |
|
|
|
.final-reveal { |
|
animation: scaleUp 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275); |
|
font-size: 2.5rem; |
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); |
|
-webkit-background-clip: text; |
|
-webkit-text-fill-color: transparent; |
|
text-align: center; |
|
margin: 2rem 0; |
|
font-weight: 800; |
|
} |
|
|
|
@keyframes scaleUp { |
|
from { transform: scale(0.8); opacity: 0; } |
|
to { transform: scale(1); opacity: 1; } |
|
} |
|
|
|
.help-chat { |
|
background: white; |
|
border-radius: 18px; |
|
padding: 1.5rem; |
|
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); |
|
border: 1px solid #e2e8f0; |
|
} |
|
|
|
.user-message { |
|
background: #667eea; |
|
color: white; |
|
border-radius: 12px 12px 0 12px; |
|
padding: 0.75rem 1rem; |
|
margin: 0.5rem 0; |
|
max-width: 80%; |
|
margin-left: auto; |
|
} |
|
|
|
.bot-message { |
|
background: #f7fafc; |
|
color: #2d3748; |
|
border-radius: 12px 12px 12px 0; |
|
padding: 0.75rem 1rem; |
|
margin: 0.5rem 0; |
|
max-width: 80%; |
|
border: 1px solid #e2e8f0; |
|
} |
|
|
|
.confidence-meter { |
|
height: 6px; |
|
background: #e2e8f0; |
|
border-radius: 3px; |
|
margin: 1rem 0; |
|
position: relative; |
|
overflow: hidden; |
|
} |
|
|
|
.confidence-fill { |
|
height: 100%; |
|
background: linear-gradient(90deg, #48bb78 0%, #38a169 100%); |
|
width: 75%; |
|
animation: confidenceAnim 1.5s ease-in-out; |
|
} |
|
|
|
@keyframes confidenceAnim { |
|
0% { width: 0; } |
|
100% { width: 75%; } |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
def show_confetti(): |
|
html(""" |
|
<canvas id="confetti-canvas" class="confetti"></canvas> |
|
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.5.1/dist/confetti.browser.min.js"></script> |
|
<script> |
|
const canvas = document.getElementById('confetti-canvas'); |
|
const confetti = confetti.create(canvas, { resize: true }); |
|
|
|
function particle(x, y) { |
|
confetti({ |
|
particleCount: 1, |
|
angle: 270, |
|
spread: 100, |
|
startVelocity: 25, |
|
origin: { x: x, y: y }, |
|
colors: ['#667eea', '#764ba2', '#48bb78'] |
|
}); |
|
} |
|
|
|
for(let i=0; i<50; i++) { |
|
setTimeout(() => { |
|
particle(Math.random(), Math.random()); |
|
}, i*50); |
|
} |
|
|
|
setTimeout(() => { canvas.remove(); }, 5000); |
|
</script> |
|
""") |
|
|
|
|
|
|
|
|
|
def main(): |
|
inject_custom_css() |
|
|
|
st.markdown('<div class="title">KASOTI</div>', unsafe_allow_html=True) |
|
st.markdown('<div class="subtitle">AI-Powered Guessing Game Challenge</div>', unsafe_allow_html=True) |
|
|
|
if 'game_state' not in st.session_state: |
|
st.session_state.game_state = "start" |
|
st.session_state.questions = [] |
|
st.session_state.current_q = 0 |
|
st.session_state.answers = [] |
|
st.session_state.conversation_history = [] |
|
st.session_state.category = None |
|
st.session_state.final_guess = None |
|
st.session_state.help_conversation = [] |
|
|
|
|
|
if st.session_state.game_state == "start": |
|
st.markdown(""" |
|
<div class="question-container"> |
|
<h3 style="color: #2d3748; margin-bottom: 1.5rem;">Welcome to <span style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent;">KASOTI</span> ๐ฏ</h3> |
|
<p style="color: #4a5568; line-height: 1.6;">Think of something and I'll try to guess it in 20 questions or less!<br> |
|
Choose from these categories:</p> |
|
<div style="margin: 1.5rem 0;"> |
|
<div style="background: #f0f4f8; padding: 1rem; border-radius: 12px; margin: 0.5rem 0;"> |
|
<strong>๐ค Person</strong><br> |
|
<span style="color: #718096;">Celebrity, fictional character, historical figure</span> |
|
</div> |
|
<div style="background: #f0f4f8; padding: 1rem; border-radius: 12px; margin: 0.5rem 0;"> |
|
<strong>๐ Place</strong><br> |
|
<span style="color: #718096;">City, country, landmark, geographical location</span> |
|
</div> |
|
<div style="background: #f0f4f8; padding: 1rem; border-radius: 12px; margin: 0.5rem 0;"> |
|
<strong>๐ฆ Object</strong><br> |
|
<span style="color: #718096;">Everyday item, tool, vehicle, etc.</span> |
|
</div> |
|
</div> |
|
</div> |
|
""", unsafe_allow_html=True) |
|
|
|
with st.form("start_form"): |
|
category_input = st.text_input("Enter category (person/place/object):", |
|
key="start_input").strip().lower() |
|
if st.form_submit_button("Start Game", use_container_width=True): |
|
if not category_input: |
|
st.error("Please enter a category!") |
|
elif category_input not in ["person", "place", "object"]: |
|
st.error("Please enter either 'person', 'place', or 'object'!") |
|
else: |
|
st.session_state.category = category_input |
|
first_question = ask_llama([ |
|
{"role": "user", "content": "Ask your first strategic yes/no question."} |
|
], category_input) |
|
st.session_state.questions = [first_question] |
|
st.session_state.conversation_history = [ |
|
{"role": "assistant", "content": first_question} |
|
] |
|
st.session_state.game_state = "gameplay" |
|
st.experimental_rerun() |
|
|
|
|
|
elif st.session_state.game_state == "gameplay": |
|
|
|
progress = (st.session_state.current_q + 1) / 20 |
|
st.markdown(f""" |
|
<div class="progress-bar"> |
|
<div class="progress-fill" style="width: {progress * 100}%"></div> |
|
</div> |
|
<div style="text-align: center; color: #4a5568; margin-bottom: 1.5rem;"> |
|
Question {st.session_state.current_q + 1} of 20 |
|
</div> |
|
""", unsafe_allow_html=True) |
|
|
|
current_question = st.session_state.questions[st.session_state.current_q] |
|
|
|
if "Final Guess:" in current_question: |
|
st.session_state.final_guess = current_question.split("Final Guess:")[1].strip() |
|
st.session_state.game_state = "confirm_guess" |
|
st.experimental_rerun() |
|
|
|
st.markdown(f""" |
|
<div class="question-container"> |
|
<div class="question-text">{current_question}</div> |
|
</div> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
st.markdown(""" |
|
<div class="confidence-meter"> |
|
<div class="confidence-fill"></div> |
|
</div> |
|
<div style="text-align: right; color: #718096; font-size: 0.9rem;"> |
|
AI Confidence Level: 75% |
|
</div> |
|
""", unsafe_allow_html=True) |
|
|
|
with st.form("answer_form"): |
|
answer_input = st.text_input("Your answer (yes/no/both):", |
|
key=f"answer_{st.session_state.current_q}", |
|
placeholder="Type your answer here...").strip().lower() |
|
if st.form_submit_button("Submit Answer", use_container_width=True): |
|
|
|
|
|
|
|
|
|
|
|
with st.expander("๐ฌ Need Help? Ask the AI Assistant", expanded=False): |
|
st.markdown('<div class="help-chat">', unsafe_allow_html=True) |
|
help_query = st.text_input("Type your question:", key="help_query", |
|
placeholder="How should I answer this?") |
|
if st.button("Send", use_container_width=True, key="send_help"): |
|
|
|
if st.session_state.help_conversation: |
|
for msg in st.session_state.help_conversation: |
|
st.markdown(f'<div class="user-message">{msg["query"]}</div>', unsafe_allow_html=True) |
|
st.markdown(f'<div class="bot-message">{msg["response"]}</div>', unsafe_allow_html=True) |
|
st.markdown('</div>', unsafe_allow_html=True) |
|
|
|
if __name__ == "__main__": |
|
main() |