File size: 4,544 Bytes
6339572 | 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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | 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
|