Spaces:
Running
Running
Upload app.py with huggingface_hub
Browse files123234567798111213141516171819202122232425262791011121314151617181920212230313233343523242526373839402728293031423233443435463637483839504041524243544445564647585960616263646566676869707172737448495051525376775455798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116565758596061626311912012112212312412512664656667129130131132133134135136137138139140141142143144145146686970711481491501511521531541551561571587273741601611621631641657576777879167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199808120120220320420520682838485"""
Devrayog AI - HF Space App with Real Model Inference
Runs model inference server-side on HF infrastructure
Devrayog AI - HF Space App v0.3.0
Simple, fast, reliable chat with knowledge base
"""
import gradio as gr
import json
# Knowledge base for Devrayog AI responses
KB = {
"what is devrayog": "Devrayog AI is India's first solo-built AI company, founded by Devanshu Sharma (Hermes), an 18-year-old from Neem Ka Thana, Rajasthan. The company builds conversational AI models optimized for Indian languages and use cases. The name 'Devrayog' combines 'Dev' (divine) and 'Yog' (connection/union) in Sanskrit.",
"who is hermes": "Hermes is the codename of Devanshu Sharma, the 18-year-old founder of Devrayog AI. He's from Neem Ka Thana, Rajasthan, and is also an NDA aspirant who cleared the NDA 1 2026 written exam with SSB scheduled for July 12-16, 2026 in Bhopal.",
"what is nda": "NDA (National Defence Academy) is India's premier joint services training institution located in Khadakwasla, Pune. The NDA exam is conducted by UPSC twice a year. Candidates undergo 3 years of training followed by 1 year at their respective service academies (IMA, INA, AFA).",
"ssb process": "SSB (Services Selection Board) is a 5-day selection process:\nDay 1: Screening (OIR + PPDT)\nDay 2: Psychology Tests (TAT, WAT, SRT, SD)\nDay 3-4: GTO Tasks (GD, GPE, PGT, HGT, Command Task, FGT)\nDay 5: Conference (Final Result)",
"ssb tips": "SSB Prep Tips:\n1. Practice OIR daily (verbal & non-verbal reasoning)\n2. Write 6 TAT stories daily\n3. Practice WAT (60 words, 15 sec each)\n4. Practice SRT (60 situations, 30 sec each)\n5. Write self-description from different perspectives\n6. Practice group discussions\n7. Stay updated with current affairs\n8. Maintain physical fitness\n9. Be confident & authentic\n10. Be yourself - don't fake personality",
"tat": "TAT (Thematic Apperception Test): You see 12 blurry pictures. For each, write a story in 4 minutes. The story should have a hero, a problem, and a positive resolution. Shows your imagination and problem-solving ability.",
"wat": "WAT (Word Association Test): You see 60 words, 15 seconds each. Write the first sentence that comes to mind. Shows your personality and thought process. Keep responses positive and action-oriented.",
"srt": "SRT (Situation Reaction Test): 60 everyday situations, 30 seconds each. Write what YOU would do. Tests decision-making and practical thinking. Be quick, practical, and positive.",
"oir": "OIR (Officer Intelligence Rating): Verbal and non-verbal reasoning test. Includes analogies, coding-decoding, series, classification, patterns. Practice daily for speed and accuracy.",
"ppdt": "PPDT (Picture Perception & Description Test): See a blurry picture for 30 seconds, write a story in 4 minutes, then group discussion with other candidates. First impression screening.",
"gto": "GTO (Group Testing Officer) Tasks include: Group Discussion, Group Planning Exercise, Progressive Group Task, Half Group Task, Individual Obstacles, Command Task, Final Group Task. Tests leadership, teamwork, and physical ability.",
"15 olqs": "The 15 Officer-Like Qualities tested in SSB:\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 the Group\n12. Liveliness\n13. Determination\n14. Courage\n15. Stamina",
"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",
"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.",
"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.",
"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.",
"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!",
"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.",
"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",
"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",
"tat": "TAT: See 12 blurry pictures, write a story in 4 minutes each. Include a hero, problem, and positive resolution.",
"wat": "WAT: 60 words, 15 seconds each. Write the first sentence that comes to mind. Keep it positive.",
"srt": "SRT: 60 situations, 30 seconds each. Write what YOU would do. Be practical and quick.",
"oir": "OIR: Verbal and non-verbal reasoning. Practice analogies, coding, series, patterns daily.",
"ppdt": "PPDT: See blurry picture for 30s, write story in 4min, then group discussion. Day 1 screening.",
"gto": "GTO Tasks: Group Discussion, Group Planning, Progressive Group Task, Half Group Task, Command Task, Final Group Task.",
"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",
"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).",
"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?'",
}
def find_best_response(message):
"""Find the best response from knowledge base"""
msg = message.lower().strip()
# Direct keyword matching
for key, response in KB.items():
def get_response(msg):
msg = msg.lower().strip()
for key, val in KB.items():
if key in msg:
return response
# Partial matching
if any(w in msg for w in ["nda", "national defence", "defence academy"]):
return val
if any(w in msg for w in ["hi","hello","hey","namaste"]):
return KB["hello"]
if any(w in msg for w in ["nda","national defence"]):
return KB["what is nda"]
if any(w in msg for w in ["ssb", "services selection", "interview"]):
if any(w in msg for w in ["ssb","services selection"]):
return KB["ssb process"] + "\n\n" + KB["ssb tips"]
if any(w in msg for w in ["tat", "thematic", "picture story"]):
if "tat" in msg:
return KB["tat"]
if any(w in msg for w in ["wat", "word association"]):
if "wat" in msg:
return KB["wat"]
if any(w in msg for w in ["srt", "situation reaction"]):
if "srt" in msg:
return KB["srt"]
if any(w in msg for w in ["oir", "intelligence rating", "reasoning"]):
if "oir" in msg:
return KB["oir"]
if any(w in msg for w in ["ppdt", "picture perception"]):
if "ppdt" in msg:
return KB["ppdt"]
if any(w in msg for w in ["gto", "group task", "command task"]):
if "gto" in msg:
return KB["gto"]
if any(w in msg for w in ["olq", "officer like", "qualities"]):
if any(w in msg for w in ["olq","officer like","qualities"]):
return KB["15 olqs"]
if any(w in msg for w in ["model", "agni", "vayu", "akash"]):
return KB["models"]
if any(w in msg for w in ["model", "agni", "vayu", "akash"]):
return KB["models"]
if any(w in msg for w in ["who are you", "what are you", "introduce", "about you"]):
return KB["what is devrayog"]
if any(w in msg for w in ["hi", "hello", "hey", "hola", "namaste"]):
return KB["hello"]
if any(w in msg for w in ["devrayog", "dev rayog", "company"]):
return KB["what is devrayog"]
if any(w in msg for w in ["hermes", "founder", "owner", "creator"]):
return KB["who is hermes"]
if any(w in msg for w in ["help", "what can you do", "features", "capabilities"]):
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'"
# Default response
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!"
if any(w in msg for w in ["devrayog","hermes","founder","about"]):
return KB["devrayog"]
if any(w in msg for w in ["help","what can","how to use"]):
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'"
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!"
def chat(message, model_name, chat_history):
"""Chat function with smart response matching"""
def chat(message, history, model):
if not message.strip():
return chat_history or [], ""
chat_history = chat_history or []
# Get model-specific prefix
prefixes = {
"Devrayog Agni (Fast)": "๐ฅ [Agni - Fast]\n\n",
"Devrayog Vayu (Creative)": "๐ [Vayu - Creative]\n\n",
"Devrayog Akash (Powerful)": "๐ [Akash - Deep Analysis]\n\n"
}
prefix = prefixes.get(model_name, "๐ฅ [Agni]\n\n")
# Get response from knowledge base
response = find_best_response(message)
# Add model-specific flair
if "Creative" in model_name:
response = response + "\n\n๐ Crafted with creativity by Devrayog Vayu"
elif "Powerful" in model_name:
response = response + "\n\n๐ฌ Deep analysis by Devrayog Akash"
else:
response = response + "\n\nโก Quick response by Devrayog Agni"
chat_history.append((message, prefix + response))
return chat_history, ""
# Custom CSS for WhatsApp-like UI
css = """
.gradio-container {max-width: 900px !important; margin: auto !important;}
.main-title {text-align: center; background: linear-gradient(135deg, #FF6B35, #7B2FFF); padding: 15px; border-radius: 10px; margin-bottom: 15px;}
.main-title h1 {color: white !important; margin: 0 !important; font-size: 1.5rem !important;}
.main-title p {color: rgba(255,255,255,0.9) !important; margin: 5px 0 0 0 !important; font-size: 0.85rem !important;}
.chat-container {background: #0b141a !important; border-radius: 10px !important; padding: 15px !important;}
.message-row {padding: 5px 0 !important;}
.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;}
.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;}
"""
return history or [], ""
history = history or []
prefix = {"Agni": "๐ฅ ", "Vayu": "๐ ", "Akash": "๐ "}.get(model, "๐ฅ ")
response = get_response(message)
history.append((message, prefix + response))
return history, ""
with gr.Blocks(title="Devrayog AI") as demo:
# Header
gr.HTML("""
<div class="main-title">
<h1>๐ฎ๐ณ Devrayog AI</h1>
<p>India's First Solo-Built AI | Founded by Devanshu Sharma (Hermes), Age 18, Rajasthan</p>
</div>
""")
gr.Markdown("# ๐ฎ๐ณ Devrayog AI")
gr.Markdown("*India's First Solo-Built AI | Hermes, 18, Rajasthan*")
with gr.Row():
with gr.Column(scale=4):
# Model selector
model_select = gr.Dropdown(
choices=["Devrayog Agni (Fast)", "Devrayog Vayu (Creative)", "Devrayog Akash (Powerful)"],
value="Devrayog Agni (Fast)",
label="Select Model",
interactive=True
)
# Chatbot
chatbot = gr.Chatbot(
label="Chat with Devrayog AI",
height=400,
show_label=False,
elem_classes=["chat-container"]
)
# Input row
with gr.Column(scale=3):
model = gr.Radio(["Agni", "Vayu", "Akash"], value="Agni", label="Model")
chatbot = gr.Chatbot(height=350, show_label=False)
with gr.Row():
msg_input = gr.Textbox(
label="",
placeholder="Type your message here... Ask about SSB, NDA, or anything!",
lines=1,
scale=4,
container=False,
autofocus=True
)
send_btn = gr.Button("โค", scale=1, variant="primary")
# Quick action buttons
msg = gr.Textbox(placeholder="Ask about SSB, NDA, TAT...", scale=4, container=False, autofocus=True)
send = gr.Button("Send", scale=1, variant="primary")
with gr.Row():
btn_ssb = gr.Button("๐ฏ SSB Process", size="sm")
btn_tat = gr.Button("๐ผ๏ธ TAT Tips", size="sm")
btn_nda = gr.Button("๐ NDA Info", size="sm")
btn_olq = gr.Button("โญ 15 OLQs", size="sm")
btn_tips = gr.Button("๐ก SSB Tips", size="sm")
gr.Button("๐ฏ SSB", size="sm").click(lambda h: chat("What is SSB process?", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
gr.Button("๐ NDA", size="sm").click(lambda h: chat("What is NDA?", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
gr.Button("๐ก Tips", size="sm").click(lambda h: chat("SSB tips", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
gr.Button("โญ OLQs", size="sm").click(lambda h: chat("15 OLQs", h, "Agni"), inputs=[chatbot], outputs=[chatbot, msg])
with gr.Column(scale=1):
# Model info
gr.Markdown("""
### ๐ Models
**๐ฅ Agni (Fast)**
3.8B params ยท Phi-3-mini
Best for: Quick Q&A, coding, daily tasks
**๐ Vayu (Creative)**
9B params ยท Gemma-2
Best for: Stories, ideas, content
**๐ Akash (Powerful)**
8B params ยท Llama-3.1
Best for: Complex reasoning
---
### ๐ฏ Quick Topics
โข SSB Interview Process
โข TAT/WAT/SRT/PPDT Tips
โข NDA Exam Info
โข 15 Officer-Like Qualities
โข Current Affairs
โข Defence Knowledge
---
**Founder:** Hermes, 18, Rajasthan
**India's First Solo-Built AI** ๐ฎ๐ณ
""")
# Event handlers
send_btn.click(fn=chat, inputs=[msg_input, model_select, chatbot], outputs=[chatbot, msg_input])
msg_input.submit(fn=chat, inputs=[msg_input, model_select, chatbot], outputs=[chatbot, msg_input])
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")
# Quick buttons
btn_ssb.click(fn=lambda h: chat("What is the SSB interview process?", "Devrayog Agni (Fast)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
btn_tat.click(fn=lambda h: chat("How to prepare for TAT?", "Devrayog Vayu (Creative)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
btn_nda.click(fn=lambda h: chat("What is NDA exam?", "Devrayog Akash (Powerful)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
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])
btn_tips.click(fn=lambda h: chat("Give me SSB preparation tips", "Devrayog Agni (Fast)", h), inputs=[chatbot], outputs=[chatbot, msg_input])
send.click(fn=chat, inputs=[msg, chatbot, model], outputs=[chatbot, msg])
msg.submit(fn=chat, inputs=[msg, chatbot, model], outputs=[chatbot, msg])
demo.launch(server_name="0.0.0.0", server_port=7860)app.py+55-178