chinesemusk commited on
Commit
9993d21
·
verified ·
1 Parent(s): a7698cc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -13
app.py CHANGED
@@ -1,18 +1,59 @@
1
  import gradio as gr
 
 
2
 
3
- # Load your bio and projects
 
 
 
 
 
 
 
4
  with open("bio.txt", "r") as f:
5
  bio = f.read()
6
 
7
- def chat_with_deonai(user_input):
8
- # Simple prompt
9
- prompt = f"You are DeonAI, an assistant who knows everything about Chinese. Bio:\n{bio}\n\nUser: {user_input}\nDeonAI:"
10
-
11
- # Use a lightweight model like deepseek-chat or mistral
12
- from transformers import pipeline
13
- generator = pipeline("text-generation", model="deepseek-ai/deepseek-llm-7b-chat", max_new_tokens=150)
14
- response = generator(prompt)[0]["generated_text"].split("DeonAI:")[-1]
15
-
16
- return response.strip()
17
-
18
- gr.ChatInterface(chat_with_deonai, title="Talk to DeonAI", description="Ask anything about Chinese").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ import os
3
+ import google.generativeai as genai
4
 
5
+ # Get Gemini API key from Hugging Face Secrets
6
+ GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
7
+
8
+ # Configure Gemini
9
+ genai.configure(api_key=GEMINI_API_KEY)
10
+ model = genai.GenerativeModel("gemini-1.5-flash")
11
+
12
+ # Load bio context
13
  with open("bio.txt", "r") as f:
14
  bio = f.read()
15
 
16
+ # Define allowed topics
17
+ ALLOWED_TOPICS = [
18
+ "ai", "machine learning", "ml", "data science", "blockchain", "web3",
19
+ "chinese", "turing project", "deonai", "rust", "llm", "llms", "financai", "eucossa"
20
+ ]
21
+
22
+ def is_on_topic(message: str):
23
+ message = message.lower()
24
+ return any(topic in message for topic in ALLOWED_TOPICS)
25
+
26
+ # Define DeonAI logic
27
+ def chat_with_deonai(message, history):
28
+ if not is_on_topic(message):
29
+ return "I'm DeonAI! I'm specialized in Chinese’s work, AI, ML, and Web3. Please ask me something in those areas. 😊"
30
+
31
+ prompt = f"""
32
+ You are DeonAI, a creative, helpful AI assistant embedded in a portfolio website.
33
+
34
+ You ONLY discuss topics related to:
35
+ - Chinese (the portfolio owner)
36
+ - His biography and projects
37
+ - AI, Machine Learning, LLMs, Blockchain, and Web3
38
+ - Ongoing projects like Turing Project, DeonAI, FinancAI, etc.
39
+
40
+ Here is your background info:
41
+ {bio}
42
+
43
+ Now respond helpfully, concisely, and informatively.
44
+
45
+ User: {message}
46
+ DeonAI:
47
+ """
48
+ try:
49
+ response = model.generate_content(prompt)
50
+ return response.text.strip()
51
+ except Exception as e:
52
+ return f"Error: {str(e)}"
53
+
54
+ # Gradio chat interface
55
+ gr.ChatInterface(
56
+ fn=chat_with_deonai,
57
+ title="🤖 DeonAI",
58
+ description="Ask me anything about Chinese, AI, ML, or Web3! I'm your smart assistant 👨🏽‍💻",
59
+ ).launch()