SilverWulf212 commited on
Commit
e24d2f9
ยท
verified ยท
1 Parent(s): 1583dec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +127 -16
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-1.5-flash'
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. Answer using ONLY the provided wiki content.
 
 
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๐Ÿ“š **Sources:** " + ", ".join(set([s['source'] for s in sources]))
162
 
163
  return answer + source_list
164
 
165
  except Exception as e:
166
- return f"โŒ Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
 
168
- # Create Gradio interface (Gradio 5 compatible)
169
  demo = gr.ChatInterface(
170
  fn=chat,
171
- title="๐ŸŽฎ Dead Cells Wiki Bot",
172
- description="Ask me anything about Dead Cells! Powered by the official wiki.",
173
  examples=[
174
- "What achievements are there for beating bosses?",
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
- theme="soft"
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__":