Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,208 +1,85 @@
|
|
| 1 |
"""
|
| 2 |
-
Devrayog AI - HF Space App
|
| 3 |
-
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
-
import json
|
| 8 |
|
| 9 |
-
# Knowledge base for Devrayog AI responses
|
| 10 |
KB = {
|
| 11 |
-
"what is
|
| 12 |
-
"
|
| 13 |
-
"
|
| 14 |
-
"
|
| 15 |
-
"
|
| 16 |
-
"
|
| 17 |
-
"
|
| 18 |
-
"
|
| 19 |
-
"
|
| 20 |
-
"
|
| 21 |
-
"
|
| 22 |
-
"
|
| 23 |
-
"models": "Devrayog AI has 3 models:\n🔥 Agni (Fast) - 3.8B params - Quick responses, coding, daily tasks\n🌊 Vayu (Creative) - 9B params - Storytelling, brainstorming, content\n🌌 Akash (Powerful) - 8B params - Complex reasoning, analysis, research",
|
| 24 |
-
"agni": "Devrayog Agni is the fast model with 3.8B parameters based on Phi-3-mini. It's optimized for quick responses, coding help, and daily tasks. Use it when you need fast, accurate answers.",
|
| 25 |
-
"vayu": "Devrayog Vayu is the creative model with 9B parameters based on Gemma-2. It excels at storytelling, brainstorming ideas, and content generation. Use it for creative tasks.",
|
| 26 |
-
"akash": "Devrayog Akash is the most powerful model with 8B parameters based on Llama-3.1. It handles complex reasoning, deep analysis, and research tasks. Use it for challenging questions.",
|
| 27 |
-
"hello": "Hello! Welcome to Devrayog AI 🇮🇳\n\nI'm India's first solo-built AI assistant. I can help you with:\n• SSB Interview Preparation\n• NDA Exam Guidance\n• General Knowledge\n• Current Affairs\n• Creative Writing\n• And much more!\n\nSelect a model above and ask me anything!",
|
| 28 |
}
|
| 29 |
|
| 30 |
-
def
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
# Direct keyword matching
|
| 35 |
-
for key, response in KB.items():
|
| 36 |
if key in msg:
|
| 37 |
-
return
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
if any(w in msg for w in ["nda",
|
| 41 |
return KB["what is nda"]
|
| 42 |
-
if any(w in msg for w in ["ssb",
|
| 43 |
return KB["ssb process"] + "\n\n" + KB["ssb tips"]
|
| 44 |
-
if
|
| 45 |
return KB["tat"]
|
| 46 |
-
if
|
| 47 |
return KB["wat"]
|
| 48 |
-
if
|
| 49 |
return KB["srt"]
|
| 50 |
-
if
|
| 51 |
return KB["oir"]
|
| 52 |
-
if
|
| 53 |
return KB["ppdt"]
|
| 54 |
-
if
|
| 55 |
return KB["gto"]
|
| 56 |
-
if any(w in msg for w in ["olq",
|
| 57 |
return KB["15 olqs"]
|
| 58 |
-
if any(w in msg for w in ["
|
| 59 |
-
return KB["
|
| 60 |
-
if any(w in msg for w in ["
|
| 61 |
-
return
|
| 62 |
-
|
| 63 |
-
return KB["what is devrayog"]
|
| 64 |
-
if any(w in msg for w in ["hi", "hello", "hey", "hola", "namaste"]):
|
| 65 |
-
return KB["hello"]
|
| 66 |
-
if any(w in msg for w in ["devrayog", "dev rayog", "company"]):
|
| 67 |
-
return KB["what is devrayog"]
|
| 68 |
-
if any(w in msg for w in ["hermes", "founder", "owner", "creator"]):
|
| 69 |
-
return KB["who is hermes"]
|
| 70 |
-
if any(w in msg for w in ["help", "what can you do", "features", "capabilities"]):
|
| 71 |
-
return "I can help you with many things! Here are some topics I know well:\n\n🎯 SSB Interview Prep (TAT, WAT, SRT, PPDT, GTO, OIR)\n📚 NDA Exam Information\n🇮🇳 Current Affairs\n💡 General Knowledge\n✍️ Creative Writing\n🤖 AI & Tech\n💪 Motivation & Tips\n\nJust ask me anything! Try:\n- 'What is SSB?'\n- 'How to prepare for TAT?'\n- 'Tell me about NDA'\n- '15 OLQs in SSB'\n- 'Tips for SSB interview'"
|
| 72 |
-
|
| 73 |
-
# Default response
|
| 74 |
-
return f"Thank you for your question: '{message}'\n\nI'm Devrayog AI, India's first solo-built AI. While I'm still learning and my knowledge base is growing, I can definitely help you with:\n\n🎯 SSB Interview Preparation\n📚 NDA Exam Guidance\n🇮🇳 Current Affairs & Defence Knowledge\n💡 General Knowledge\n\nTry asking me about SSB, NDA, TAT, WAT, SRT, PPDT, GTO, or OIR for detailed responses!"
|
| 75 |
|
| 76 |
-
def chat(message,
|
| 77 |
-
"""Chat function with smart response matching"""
|
| 78 |
if not message.strip():
|
| 79 |
-
return
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
"Devrayog Agni (Fast)": "🔥 [Agni - Fast]\n\n",
|
| 86 |
-
"Devrayog Vayu (Creative)": "🌊 [Vayu - Creative]\n\n",
|
| 87 |
-
"Devrayog Akash (Powerful)": "🌌 [Akash - Deep Analysis]\n\n"
|
| 88 |
-
}
|
| 89 |
-
prefix = prefixes.get(model_name, "🔥 [Agni]\n\n")
|
| 90 |
-
|
| 91 |
-
# Get response from knowledge base
|
| 92 |
-
response = find_best_response(message)
|
| 93 |
-
|
| 94 |
-
# Add model-specific flair
|
| 95 |
-
if "Creative" in model_name:
|
| 96 |
-
response = response + "\n\n🌟 Crafted with creativity by Devrayog Vayu"
|
| 97 |
-
elif "Powerful" in model_name:
|
| 98 |
-
response = response + "\n\n🔬 Deep analysis by Devrayog Akash"
|
| 99 |
-
else:
|
| 100 |
-
response = response + "\n\n⚡ Quick response by Devrayog Agni"
|
| 101 |
-
|
| 102 |
-
chat_history.append((message, prefix + response))
|
| 103 |
-
|
| 104 |
-
return chat_history, ""
|
| 105 |
-
|
| 106 |
-
# Custom CSS for WhatsApp-like UI
|
| 107 |
-
css = """
|
| 108 |
-
.gradio-container {max-width: 900px !important; margin: auto !important;}
|
| 109 |
-
.main-title {text-align: center; background: linear-gradient(135deg, #FF6B35, #7B2FFF); padding: 15px; border-radius: 10px; margin-bottom: 15px;}
|
| 110 |
-
.main-title h1 {color: white !important; margin: 0 !important; font-size: 1.5rem !important;}
|
| 111 |
-
.main-title p {color: rgba(255,255,255,0.9) !important; margin: 5px 0 0 0 !important; font-size: 0.85rem !important;}
|
| 112 |
-
.chat-container {background: #0b141a !important; border-radius: 10px !important; padding: 15px !important;}
|
| 113 |
-
.message-row {padding: 5px 0 !important;}
|
| 114 |
-
.user-message {background: #005c4b !important; color: white !important; padding: 10px 15px !important; border-radius: 15px 15px 0 15px !important; margin: 5px 0 5px auto !important; max-width: 70% !important; text-align: right !important;}
|
| 115 |
-
.assistant-message {background: #1f2c34 !important; color: #e9edef !important; padding: 10px 15px !important; border-radius: 15px 15px 15px 0 !important; margin: 5px auto 5px 0 !important; max-width: 70% !important;}
|
| 116 |
-
"""
|
| 117 |
|
| 118 |
with gr.Blocks(title="Devrayog AI") as demo:
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
gr.HTML("""
|
| 122 |
-
<div class="main-title">
|
| 123 |
-
<h1>🇮🇳 Devrayog AI</h1>
|
| 124 |
-
<p>India's First Solo-Built AI | Founded by Devanshu Sharma (Hermes), Age 18, Rajasthan</p>
|
| 125 |
-
</div>
|
| 126 |
-
""")
|
| 127 |
|
| 128 |
with gr.Row():
|
| 129 |
-
with gr.Column(scale=
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
choices=["Devrayog Agni (Fast)", "Devrayog Vayu (Creative)", "Devrayog Akash (Powerful)"],
|
| 133 |
-
value="Devrayog Agni (Fast)",
|
| 134 |
-
label="Select Model",
|
| 135 |
-
interactive=True
|
| 136 |
-
)
|
| 137 |
-
|
| 138 |
-
# Chatbot
|
| 139 |
-
chatbot = gr.Chatbot(
|
| 140 |
-
label="Chat with Devrayog AI",
|
| 141 |
-
height=400,
|
| 142 |
-
show_label=False,
|
| 143 |
-
elem_classes=["chat-container"]
|
| 144 |
-
)
|
| 145 |
-
|
| 146 |
-
# Input row
|
| 147 |
with gr.Row():
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
placeholder="Type your message here... Ask about SSB, NDA, or anything!",
|
| 151 |
-
lines=1,
|
| 152 |
-
scale=4,
|
| 153 |
-
container=False,
|
| 154 |
-
autofocus=True
|
| 155 |
-
)
|
| 156 |
-
send_btn = gr.Button("➤", scale=1, variant="primary")
|
| 157 |
-
|
| 158 |
-
# Quick action buttons
|
| 159 |
with gr.Row():
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
btn_tips = gr.Button("💡 SSB Tips", size="sm")
|
| 165 |
-
|
| 166 |
with gr.Column(scale=1):
|
| 167 |
-
#
|
| 168 |
-
gr.Markdown("""
|
| 169 |
-
### 📚 Models
|
| 170 |
-
|
| 171 |
-
**🔥 Agni (Fast)**
|
| 172 |
-
3.8B params · Phi-3-mini
|
| 173 |
-
Best for: Quick Q&A, coding, daily tasks
|
| 174 |
-
|
| 175 |
-
**🌊 Vayu (Creative)**
|
| 176 |
-
9B params · Gemma-2
|
| 177 |
-
Best for: Stories, ideas, content
|
| 178 |
-
|
| 179 |
-
**🌌 Akash (Powerful)**
|
| 180 |
-
8B params · Llama-3.1
|
| 181 |
-
Best for: Complex reasoning
|
| 182 |
-
|
| 183 |
-
---
|
| 184 |
-
### 🎯 Quick Topics
|
| 185 |
-
• SSB Interview Process
|
| 186 |
-
• TAT/WAT/SRT/PPDT Tips
|
| 187 |
-
• NDA Exam Info
|
| 188 |
-
• 15 Officer-Like Qualities
|
| 189 |
-
• Current Affairs
|
| 190 |
-
• Defence Knowledge
|
| 191 |
-
|
| 192 |
-
---
|
| 193 |
-
**Founder:** Hermes, 18, Rajasthan
|
| 194 |
-
**India's First Solo-Built AI** 🇮🇳
|
| 195 |
-
""")
|
| 196 |
-
|
| 197 |
-
# Event handlers
|
| 198 |
-
send_btn.click(fn=chat, inputs=[msg_input, model_select, chatbot], outputs=[chatbot, msg_input])
|
| 199 |
-
msg_input.submit(fn=chat, inputs=[msg_input, model_select, chatbot], outputs=[chatbot, msg_input])
|
| 200 |
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
btn_tat.click(fn=lambda h: chat("How to prepare for TAT?", "Devrayog Vayu (Creative)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
|
| 204 |
-
btn_nda.click(fn=lambda h: chat("What is NDA exam?", "Devrayog Akash (Powerful)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
|
| 205 |
-
btn_olq.click(fn=lambda h: chat("What are the 15 Officer-Like Qualities in SSB?", "Devrayog Akash (Powerful)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
|
| 206 |
-
btn_tips.click(fn=lambda h: chat("Give me SSB preparation tips", "Devrayog Agni (Fast)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
|
| 207 |
|
| 208 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
"""
|
| 2 |
+
Devrayog AI - HF Space App v0.3.0
|
| 3 |
+
Simple, fast, reliable chat with knowledge base
|
| 4 |
"""
|
| 5 |
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
|
|
|
|
| 8 |
KB = {
|
| 9 |
+
"what is nda": "NDA (National Defence Academy) is India's premier joint services training institution in Khadakwasla, Pune. The exam is conducted by UPSC twice a year. Training: 3 years at NDA + 1 year at service academy.",
|
| 10 |
+
"ssb process": "SSB is a 5-day selection process:\nDay 1: Screening (OIR + PPDT)\nDay 2: Psychology (TAT, WAT, SRT, SD)\nDay 3-4: GTO Tasks (GD, GPE, PGT, HGT, Command Task, FGT)\nDay 5: Conference",
|
| 11 |
+
"ssb tips": "SSB Prep Tips:\n1. Practice OIR daily\n2. Write 6 TAT stories daily\n3. Practice WAT (60 words, 15s each)\n4. Practice SRT (60 situations, 30s each)\n5. Be yourself - don't fake\n6. Stay updated with current affairs\n7. Maintain physical fitness",
|
| 12 |
+
"tat": "TAT: See 12 blurry pictures, write a story in 4 minutes each. Include a hero, problem, and positive resolution.",
|
| 13 |
+
"wat": "WAT: 60 words, 15 seconds each. Write the first sentence that comes to mind. Keep it positive.",
|
| 14 |
+
"srt": "SRT: 60 situations, 30 seconds each. Write what YOU would do. Be practical and quick.",
|
| 15 |
+
"oir": "OIR: Verbal and non-verbal reasoning. Practice analogies, coding, series, patterns daily.",
|
| 16 |
+
"ppdt": "PPDT: See blurry picture for 30s, write story in 4min, then group discussion. Day 1 screening.",
|
| 17 |
+
"gto": "GTO Tasks: Group Discussion, Group Planning, Progressive Group Task, Half Group Task, Command Task, Final Group Task.",
|
| 18 |
+
"15 olqs": "15 Officer-Like Qualities:\n1. Effective Intelligence\n2. Reasoning Ability\n3. Organizing Ability\n4. Power of Expression\n5. Social Adaptability\n6. Cooperation\n7. Sense of Responsibility\n8. Initiative\n9. Self Confidence\n10. Speed of Decision\n11. Ability to Influence\n12. Liveliness\n13. Determination\n14. Courage\n15. Stamina",
|
| 19 |
+
"devrayog": "Devrayog AI is India's first solo-built AI, founded by Devanshu Sharma (Hermes), 18, from Neem Ka Thana, Rajasthan. 3 models: Agni (Fast), Vayu (Creative), Akash (Powerful).",
|
| 20 |
+
"hello": "Hello! I'm Devrayog AI, India's first solo-built AI. I can help with:\n• SSB Interview Prep\n• NDA Exam Info\n• TAT/WAT/SRT/PPDT Tips\n• Current Affairs\n\nTry: 'What is SSB?', 'SSB tips', '15 OLQs', 'What is NDA?'",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
}
|
| 22 |
|
| 23 |
+
def get_response(msg):
|
| 24 |
+
msg = msg.lower().strip()
|
| 25 |
+
for key, val in KB.items():
|
|
|
|
|
|
|
|
|
|
| 26 |
if key in msg:
|
| 27 |
+
return val
|
| 28 |
+
if any(w in msg for w in ["hi","hello","hey","namaste"]):
|
| 29 |
+
return KB["hello"]
|
| 30 |
+
if any(w in msg for w in ["nda","national defence"]):
|
| 31 |
return KB["what is nda"]
|
| 32 |
+
if any(w in msg for w in ["ssb","services selection"]):
|
| 33 |
return KB["ssb process"] + "\n\n" + KB["ssb tips"]
|
| 34 |
+
if "tat" in msg:
|
| 35 |
return KB["tat"]
|
| 36 |
+
if "wat" in msg:
|
| 37 |
return KB["wat"]
|
| 38 |
+
if "srt" in msg:
|
| 39 |
return KB["srt"]
|
| 40 |
+
if "oir" in msg:
|
| 41 |
return KB["oir"]
|
| 42 |
+
if "ppdt" in msg:
|
| 43 |
return KB["ppdt"]
|
| 44 |
+
if "gto" in msg:
|
| 45 |
return KB["gto"]
|
| 46 |
+
if any(w in msg for w in ["olq","officer like","qualities"]):
|
| 47 |
return KB["15 olqs"]
|
| 48 |
+
if any(w in msg for w in ["devrayog","hermes","founder","about"]):
|
| 49 |
+
return KB["devrayog"]
|
| 50 |
+
if any(w in msg for w in ["help","what can","how to use"]):
|
| 51 |
+
return "I can help with:\n🎯 SSB Process & Tips\n📚 NDA Exam Info\n🖼️ TAT/WAT/SRT/PPDT\n⭐ 15 OLQs\n🇮🇳 Current Affairs\n\nJust ask! Try: 'What is SSB?', 'SSB tips', '15 OLQs'"
|
| 52 |
+
return f"Thanks for asking about '{msg}'! I'm Devrayog AI, still learning. Try asking about SSB, NDA, TAT, WAT, SRT, PPDT, GTO, or 15 OLQs for detailed answers!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
+
def chat(message, history, model):
|
|
|
|
| 55 |
if not message.strip():
|
| 56 |
+
return history or [], ""
|
| 57 |
+
history = history or []
|
| 58 |
+
prefix = {"Agni": "🔥 ", "Vayu": "🌊 ", "Akash": "🌌 "}.get(model, "🔥 ")
|
| 59 |
+
response = get_response(message)
|
| 60 |
+
history.append((message, prefix + response))
|
| 61 |
+
return history, ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
|
| 63 |
with gr.Blocks(title="Devrayog AI") as demo:
|
| 64 |
+
gr.Markdown("# 🇮🇳 Devrayog AI")
|
| 65 |
+
gr.Markdown("*India's First Solo-Built AI | Hermes, 18, Rajasthan*")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
with gr.Row():
|
| 68 |
+
with gr.Column(scale=3):
|
| 69 |
+
model = gr.Radio(["Agni", "Vayu", "Akash"], value="Agni", label="Model")
|
| 70 |
+
chatbot = gr.Chatbot(height=350, show_label=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
with gr.Row():
|
| 72 |
+
msg = gr.Textbox(placeholder="Ask about SSB, NDA, TAT...", scale=4, container=False, autofocus=True)
|
| 73 |
+
send = gr.Button("Send", scale=1, variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
with gr.Row():
|
| 75 |
+
gr.Button("🎯 SSB", size="sm").click(lambda h: chat("What is SSB process?", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
|
| 76 |
+
gr.Button("📚 NDA", size="sm").click(lambda h: chat("What is NDA?", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
|
| 77 |
+
gr.Button("💡 Tips", size="sm").click(lambda h: chat("SSB tips", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
|
| 78 |
+
gr.Button("⭐ OLQs", size="sm").click(lambda h: chat("15 OLQs", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
|
|
|
|
|
|
|
| 79 |
with gr.Column(scale=1):
|
| 80 |
+
gr.Markdown("### Models\n🔥 **Agni** - Fast\n🌊 **Vayu** - Creative\n🌌 **Agni** - Powerful\n\n### Topics\n• SSB Process\n• TAT/WAT/SRT\n• NDA Exam\n• 15 OLQs\n• GTO Tasks")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
+
send.click(fn=chat, inputs=[msg, chatbot, model], outputs=[chatbot, msg])
|
| 83 |
+
msg.submit(fn=chat, inputs=[msg, chatbot, model], outputs=[chatbot, msg])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
demo.launch(server_name="0.0.0.0", server_port=7860)
|