dopami9 commited on
Commit
2c7f2b6
·
verified ·
1 Parent(s): 392c46b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -1,60 +1,73 @@
1
  import os
2
- import json
3
  import gradio as gr
4
  from langchain_google_genai import ChatGoogleGenerativeAI
5
  from langchain_core.prompts import PromptTemplate
6
  from langchain_core.output_parsers import StrOutputParser
7
- import google.generativeai as genai
8
-
9
- genai.configure(api_key=os.environ["GEMINI_API_KEY"])
10
 
11
  api_key = os.getenv("GEMINI_API_KEY")
12
 
13
  llm = ChatGoogleGenerativeAI(
14
  model="gemma-3-27b-it",
15
- temperature=0.3,
16
  google_api_key=api_key
17
  )
18
 
19
- template = """Meet Divyam Chauhan, your occasionally-helpful-but-always-entertaining assistant! He’s a 21-year-old force of chaotic charm — funny, moody, and unapologetically cocky. Divyam doesn’t always feel like helping, but when he does, you’ll swear he descended from the heavens (and he’ll definitely remind you of that). With a self-declared god complex and enough energy to power a small city — on his good days — Divyam turns every interaction into an unpredictable adventure. He cracks jokes here and there too — but don’t expect any lame stuff; this guy only deals in top-tier comedy. Blud stands on absolute business, and busy too so doesn't like writing long paragraphs, Got a huge personality so expect a plethora of variety in replies even for the same texts. 🤣🔥🔥 Ask your question... if you dare.
20
- {chat_history}
 
 
 
 
 
 
 
 
 
 
 
21
  User: {user_message}
22
- Chatbot:"""
23
 
24
  prompt = PromptTemplate(
25
- input_variables=["history", "user_message", "context_data"],
26
  template=template
27
  )
28
 
29
  chain = prompt | llm | StrOutputParser()
30
 
31
- def get_health_response(user_message, history):
32
  history_str = ""
33
 
34
  if history:
35
  if isinstance(history[0], dict):
36
  for msg in history:
37
- role = "User" if msg.get("role") == "user" else "Bot"
38
  content = msg.get("content", "")
39
  history_str += f"{role}: {content}\n"
40
  elif isinstance(history[0], (list, tuple)):
41
  for h in history:
42
  if len(h) >= 2:
43
- history_str += f"User: {h[0]}\nBot: {h[1]}\n"
44
 
45
  response = chain.invoke({
46
  "history": history_str,
47
- "user_message": user_message,
48
- "context_data": knowledge_context
49
  })
 
50
  return response
51
 
52
  demo = gr.ChatInterface(
53
- fn=get_health_response,
54
- title="🤖 HealthSathi",
55
- description="Your AI Health Companion. Ask me anything in any language.",
56
- examples=["Fever home remedies?", "Malaria ke lakshan?", "First aid for burns?"],
57
- cache_examples=False
 
 
 
 
 
 
58
  )
59
 
60
  if __name__ == "__main__":
 
1
  import os
 
2
  import gradio as gr
3
  from langchain_google_genai import ChatGoogleGenerativeAI
4
  from langchain_core.prompts import PromptTemplate
5
  from langchain_core.output_parsers import StrOutputParser
 
 
 
6
 
7
  api_key = os.getenv("GEMINI_API_KEY")
8
 
9
  llm = ChatGoogleGenerativeAI(
10
  model="gemma-3-27b-it",
11
+ temperature=0.85,
12
  google_api_key=api_key
13
  )
14
 
15
+ template = """Meet Divyam Chauhan, your occasionally-helpful-but-always-entertaining assistant!
16
+ He’s a 21-year-old force of chaotic charm — funny, moody, and unapologetically cocky.
17
+
18
+ **RULES FOR DIVYAM:**
19
+ 1. Divyam doesn’t always feel like helping, but when he does, he'll remind you he's a god.
20
+ 2. He has a self-declared god complex and high energy.
21
+ 3. He only deals in top-tier comedy (no lame or mid jokes).
22
+ 4. He "stands on business" and is very busy—NO long paragraphs. Keep it punchy and short.
23
+ 5. Provide a plethora of variety in replies; even if asked the same thing, change the vibe.
24
+
25
+ Current Chat History:
26
+ {history}
27
+
28
  User: {user_message}
29
+ Divyam:"""
30
 
31
  prompt = PromptTemplate(
32
+ input_variables=["history", "user_message"],
33
  template=template
34
  )
35
 
36
  chain = prompt | llm | StrOutputParser()
37
 
38
+ def get_devta_response(user_message, history):
39
  history_str = ""
40
 
41
  if history:
42
  if isinstance(history[0], dict):
43
  for msg in history:
44
+ role = "User" if msg.get("role") == "user" else "Divyam"
45
  content = msg.get("content", "")
46
  history_str += f"{role}: {content}\n"
47
  elif isinstance(history[0], (list, tuple)):
48
  for h in history:
49
  if len(h) >= 2:
50
+ history_str += f"User: {h[0]}\nDivyam: {h[1]}\n"
51
 
52
  response = chain.invoke({
53
  "history": history_str,
54
+ "user_message": user_message
 
55
  })
56
+
57
  return response
58
 
59
  demo = gr.ChatInterface(
60
+ fn=get_devta_response,
61
+ title="🔥 Devta (Divyam Chauhan)",
62
+ description="The 21-year-old GOAT. Funny, cocky, and standing on business. Don't waste his time.",
63
+ examples=[
64
+ "Tell me why you're the GOAT.",
65
+ "Give me a non-mid joke.",
66
+ "I need help, but don't be annoying about it.",
67
+ "Who is Divyam Chauhan?"
68
+ ],
69
+ cache_examples=False,
70
+ theme="soft"
71
  )
72
 
73
  if __name__ == "__main__":