ChatMate / app.py
Haridev100's picture
Create app.py
6339572 verified
Raw History Blame Contribute Delete
4.54 kB
import os
import google.generativeai as genai
import gradio as gr
# ==========================================
# 1. SYSTEM CONFIGURATION (HF SAFE)
# ==========================================
API_KEY = os.getenv("GEMINI_API_KEY") # Hugging Face Secret
genai.configure(api_key=API_KEY)
MODEL_NAME = "gemini-2.5-flash-lite"
def chatmate_chat(message, history):
try:
model = genai.GenerativeModel(MODEL_NAME)
prompt = message["text"] if isinstance(message, dict) else message
response = model.generate_content(prompt)
return response.text or "ChatMate: No response generated."
except Exception as e:
return f"ERROR: {str(e)}"
# ==========================================
# 2. CYBER-GLASS + ROBOT UI
# ==========================================
custom_css = """
@import url('https://fonts.googleapis.com/css2?family=Orbitron:wght@400;900&family=Montserrat:wght@300;600&display=swap');
.gradio-container {
height: 100dvh !important;
background: radial-gradient(circle at top right, #0f172a, #020617) !important;
font-family: 'Montserrat', sans-serif !important;
}
#main-layout {
height: 100%;
padding: 10px;
}
.side-panel {
background: rgba(255, 255, 255, 0.04);
backdrop-filter: blur(15px);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 20px;
padding: 25px;
height: 100%;
text-align: center;
box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}
.brand-label {
font-size: 11px;
color: #94a3b8;
letter-spacing: 4px;
}
.main-title {
font-family: 'Orbitron', sans-serif;
font-weight: 900;
font-size: 32px;
background: linear-gradient(to right, #22d3ee, #818cf8);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
letter-spacing: 2px;
}
/* ==========================
CUSTOM CHATMATE ROBOT
========================== */
.robot-container {
width: 110px;
margin: 28px auto;
animation: jump 1.6s infinite ease-in-out;
}
@keyframes jump {
0% { transform: translateY(0); }
30% { transform: translateY(-20px); }
50% { transform: translateY(0); }
70% { transform: translateY(-8px); }
100% { transform: translateY(0); }
}
.robot-face {
width: 110px;
height: 90px;
background: linear-gradient(145deg, #1e293b, #020617);
border-radius: 18px;
border: 2px solid #22d3ee;
box-shadow: 0 0 25px rgba(34,211,238,0.6);
position: relative;
}
/* Eyes */
.eye {
width: 14px;
height: 14px;
background: #22d3ee;
border-radius: 50%;
position: absolute;
top: 30px;
box-shadow: 0 0 10px #22d3ee;
animation: blink 4s infinite;
}
.eye.left { left: 28px; }
.eye.right { right: 28px; }
@keyframes blink {
0%, 92%, 100% { transform: scaleY(1); }
95% { transform: scaleY(0.1); }
}
/* Mouth */
.mouth {
width: 36px;
height: 6px;
background: #818cf8;
border-radius: 10px;
position: absolute;
bottom: 16px;
left: 50%;
transform: translateX(-50%);
box-shadow: 0 0 8px #818cf8;
}
/* Antenna */
.antenna {
width: 6px;
height: 18px;
background: #22d3ee;
margin: 0 auto;
border-radius: 5px;
box-shadow: 0 0 10px #22d3ee;
}
.antenna-dot {
width: 10px;
height: 10px;
background: #22d3ee;
border-radius: 50%;
margin: -5px auto 6px auto;
box-shadow: 0 0 12px #22d3ee;
}
.dev-name {
color: #ffffff;
font-weight: 600;
font-size: 18px;
text-shadow: 0 0 10px #22d3ee;
}
.chatbot-container {
height: 100%;
border: 1px solid rgba(34, 211, 238, 0.25);
border-radius: 20px;
background: rgba(0,0,0,0.25);
}
"""
# ==========================================
# 3. INTERFACE
# ==========================================
with gr.Blocks(css=custom_css, title="ChatMate | NXTWAVE ROBOTICS", fill_height=True) as demo:
with gr.Row(elem_id="main-layout", equal_height=True):
# LEFT PANEL
with gr.Column(scale=1, min_width=320):
gr.HTML("""
<div class="side-panel">
<p class="brand-label">NXTWAVE ROBOTICS</p>
<h1 class="main-title">CHATMATE</h1>
<div class="robot-container">
<div class="antenna-dot"></div>
<div class="antenna"></div>
<div class="robot-face">
<div class="eye left"></div>
<div class="eye right"></div>
<div class="mo