Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -117,7 +117,7 @@ except Exception as e:
|
|
| 117 |
print(f"โ
Database created! {chunk_id} chunks indexed from {len(wiki_files)} files")
|
| 118 |
|
| 119 |
# Gemini model
|
| 120 |
-
available_model = 'gemini-
|
| 121 |
|
| 122 |
def get_embedding(text):
|
| 123 |
"""Generate embedding for a text string"""
|
|
@@ -138,46 +138,157 @@ def chat(message, history):
|
|
| 138 |
sources = results['metadatas'][0]
|
| 139 |
|
| 140 |
if not relevant_chunks:
|
| 141 |
-
return "I couldn't find any relevant information in the wiki."
|
| 142 |
|
| 143 |
# Build context
|
| 144 |
context = "\n\n---\n\n".join(relevant_chunks)
|
| 145 |
|
| 146 |
# Ask Gemini
|
| 147 |
model = genai.GenerativeModel(available_model)
|
| 148 |
-
prompt = f"""You are a Dead Cells expert
|
|
|
|
|
|
|
| 149 |
|
| 150 |
Wiki Content:
|
| 151 |
{context}
|
| 152 |
|
| 153 |
Question: {message}
|
| 154 |
|
| 155 |
-
Answer based ONLY on the wiki content above:"""
|
| 156 |
|
| 157 |
response = model.generate_content(prompt)
|
| 158 |
answer = response.text
|
| 159 |
|
| 160 |
-
# Add sources
|
| 161 |
-
source_list = "\n\n
|
| 162 |
|
| 163 |
return answer + source_list
|
| 164 |
|
| 165 |
except Exception as e:
|
| 166 |
-
return f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
-
# Create Gradio interface
|
| 169 |
demo = gr.ChatInterface(
|
| 170 |
fn=chat,
|
| 171 |
-
title="
|
| 172 |
-
description="Ask me anything about Dead Cells! Powered by the official wiki.",
|
| 173 |
examples=[
|
| 174 |
-
"What
|
| 175 |
-
"Tell me about the Hand of the King",
|
| 176 |
-
"How does malaise work?",
|
| 177 |
-
"What are boss stem cells?",
|
| 178 |
-
"List some brutality weapons"
|
|
|
|
| 179 |
],
|
| 180 |
-
|
| 181 |
)
|
| 182 |
|
| 183 |
if __name__ == "__main__":
|
|
|
|
| 117 |
print(f"โ
Database created! {chunk_id} chunks indexed from {len(wiki_files)} files")
|
| 118 |
|
| 119 |
# Gemini model
|
| 120 |
+
available_model = 'gemini-pro'
|
| 121 |
|
| 122 |
def get_embedding(text):
|
| 123 |
"""Generate embedding for a text string"""
|
|
|
|
| 138 |
sources = results['metadatas'][0]
|
| 139 |
|
| 140 |
if not relevant_chunks:
|
| 141 |
+
return "โ๏ธ I couldn't find any relevant information in the wiki. Try asking about weapons, biomes, bosses, or game mechanics!"
|
| 142 |
|
| 143 |
# Build context
|
| 144 |
context = "\n\n---\n\n".join(relevant_chunks)
|
| 145 |
|
| 146 |
# Ask Gemini
|
| 147 |
model = genai.GenerativeModel(available_model)
|
| 148 |
+
prompt = f"""You are a Dead Cells expert assistant with a dark, edgy personality that matches the game's gothic rogue-lite atmosphere.
|
| 149 |
+
|
| 150 |
+
Answer using ONLY the provided wiki content, but make it engaging and conversational. Use emojis occasionally (โ๏ธ๐ก๏ธ๐๐ฅโก) to match the game's vibe.
|
| 151 |
|
| 152 |
Wiki Content:
|
| 153 |
{context}
|
| 154 |
|
| 155 |
Question: {message}
|
| 156 |
|
| 157 |
+
Answer based ONLY on the wiki content above. Be helpful but keep that Dead Cells edge:"""
|
| 158 |
|
| 159 |
response = model.generate_content(prompt)
|
| 160 |
answer = response.text
|
| 161 |
|
| 162 |
+
# Add sources with Dead Cells style
|
| 163 |
+
source_list = "\n\n---\n๐ก๏ธ **Wiki Sources:** " + ", ".join(set([s['source'] for s in sources]))
|
| 164 |
|
| 165 |
return answer + source_list
|
| 166 |
|
| 167 |
except Exception as e:
|
| 168 |
+
return f"๐ Error: {str(e)}"
|
| 169 |
+
|
| 170 |
+
# Custom Dead Cells CSS
|
| 171 |
+
custom_css = """
|
| 172 |
+
/* Dead Cells Dark Theme */
|
| 173 |
+
.gradio-container {
|
| 174 |
+
background: linear-gradient(135deg, #0a0a0a 0%, #1a0a1a 100%) !important;
|
| 175 |
+
font-family: 'Courier New', monospace !important;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
/* Main chat container */
|
| 179 |
+
.chat-interface {
|
| 180 |
+
background: rgba(20, 10, 30, 0.95) !important;
|
| 181 |
+
border: 2px solid #8b2e8b !important;
|
| 182 |
+
border-radius: 8px !important;
|
| 183 |
+
box-shadow: 0 0 20px rgba(139, 46, 139, 0.5) !important;
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
/* Title styling */
|
| 187 |
+
h1 {
|
| 188 |
+
color: #ff00ff !important;
|
| 189 |
+
text-shadow: 0 0 10px #8b2e8b, 0 0 20px #8b2e8b !important;
|
| 190 |
+
font-weight: bold !important;
|
| 191 |
+
letter-spacing: 2px !important;
|
| 192 |
+
}
|
| 193 |
+
|
| 194 |
+
/* Description text */
|
| 195 |
+
.description {
|
| 196 |
+
color: #d8d8d8 !important;
|
| 197 |
+
font-style: italic !important;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/* Chat messages */
|
| 201 |
+
.message {
|
| 202 |
+
background: rgba(30, 20, 40, 0.8) !important;
|
| 203 |
+
border-left: 3px solid #8b2e8b !important;
|
| 204 |
+
border-radius: 8px !important;
|
| 205 |
+
color: #e0e0e0 !important;
|
| 206 |
+
}
|
| 207 |
+
|
| 208 |
+
.message.user {
|
| 209 |
+
background: rgba(139, 46, 139, 0.2) !important;
|
| 210 |
+
border-left: 3px solid #ff00ff !important;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.message.bot {
|
| 214 |
+
background: rgba(20, 40, 60, 0.3) !important;
|
| 215 |
+
border-left: 3px solid #4a90e2 !important;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
/* Input box */
|
| 219 |
+
textarea, input {
|
| 220 |
+
background: rgba(30, 20, 40, 0.9) !important;
|
| 221 |
+
color: #e0e0e0 !important;
|
| 222 |
+
border: 2px solid #8b2e8b !important;
|
| 223 |
+
border-radius: 6px !important;
|
| 224 |
+
font-family: 'Courier New', monospace !important;
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
textarea:focus, input:focus {
|
| 228 |
+
border-color: #ff00ff !important;
|
| 229 |
+
box-shadow: 0 0 15px rgba(255, 0, 255, 0.4) !important;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
/* Buttons */
|
| 233 |
+
button {
|
| 234 |
+
background: linear-gradient(135deg, #8b2e8b 0%, #4a1a4a 100%) !important;
|
| 235 |
+
color: #ffffff !important;
|
| 236 |
+
border: 2px solid #8b2e8b !important;
|
| 237 |
+
border-radius: 6px !important;
|
| 238 |
+
font-weight: bold !important;
|
| 239 |
+
text-transform: uppercase !important;
|
| 240 |
+
letter-spacing: 1px !important;
|
| 241 |
+
transition: all 0.3s ease !important;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
button:hover {
|
| 245 |
+
background: linear-gradient(135deg, #ff00ff 0%, #8b2e8b 100%) !important;
|
| 246 |
+
box-shadow: 0 0 20px rgba(255, 0, 255, 0.6) !important;
|
| 247 |
+
transform: translateY(-2px) !important;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
/* Example buttons */
|
| 251 |
+
.example-btn {
|
| 252 |
+
background: rgba(139, 46, 139, 0.2) !important;
|
| 253 |
+
border: 1px solid #8b2e8b !important;
|
| 254 |
+
color: #e0e0e0 !important;
|
| 255 |
+
}
|
| 256 |
+
|
| 257 |
+
.example-btn:hover {
|
| 258 |
+
background: rgba(255, 0, 255, 0.3) !important;
|
| 259 |
+
border-color: #ff00ff !important;
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
/* Scrollbar */
|
| 263 |
+
::-webkit-scrollbar {
|
| 264 |
+
width: 10px;
|
| 265 |
+
background: rgba(20, 10, 30, 0.8);
|
| 266 |
+
}
|
| 267 |
+
|
| 268 |
+
::-webkit-scrollbar-thumb {
|
| 269 |
+
background: linear-gradient(180deg, #8b2e8b 0%, #4a1a4a 100%);
|
| 270 |
+
border-radius: 5px;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
::-webkit-scrollbar-thumb:hover {
|
| 274 |
+
background: linear-gradient(180deg, #ff00ff 0%, #8b2e8b 100%);
|
| 275 |
+
}
|
| 276 |
+
"""
|
| 277 |
|
| 278 |
+
# Create Gradio interface with Dead Cells theme
|
| 279 |
demo = gr.ChatInterface(
|
| 280 |
fn=chat,
|
| 281 |
+
title="โ๏ธ DEAD CELLS WIKI BOT ๐",
|
| 282 |
+
description="๐ก๏ธ Ask me anything about Dead Cells! Powered by 554 wiki pages from the official Dead Cells wiki. ๐ฅ",
|
| 283 |
examples=[
|
| 284 |
+
"โ๏ธ What's the best survival build?",
|
| 285 |
+
"๐ Tell me about the Hand of the King boss",
|
| 286 |
+
"๐ฉธ How does malaise work?",
|
| 287 |
+
"๐ What are boss stem cells?",
|
| 288 |
+
"๐ก๏ธ List some brutality weapons",
|
| 289 |
+
"๐ฐ What biomes are in the game?"
|
| 290 |
],
|
| 291 |
+
css=custom_css
|
| 292 |
)
|
| 293 |
|
| 294 |
if __name__ == "__main__":
|