NithikaShree commited on
Commit
cc9edca
·
verified ·
1 Parent(s): 9175694

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -83
app.py CHANGED
@@ -1,97 +1,37 @@
1
  import os
2
  import gradio as gr
3
  from langchain_groq import ChatGroq
4
- from langchain_tavily import TavilySearch
 
 
 
 
 
 
 
 
5
 
6
- # Load secrets from Hugging Face
7
  groq_api_key = os.environ.get("GROQ_API_KEY")
8
- tavily_api_key = os.environ.get("TAVILY_API_KEY")
9
 
10
- # Initialize LLM
11
  llm = ChatGroq(
12
  model_name="openai/gpt-oss-120b",
13
- temperature=0,
14
  groq_api_key=groq_api_key
15
  )
16
 
17
- # Initialize search
18
- search = TavilySearch(
19
- max_results=5,
20
- tavily_api_key=tavily_api_key
21
- )
22
-
23
- def search_agent(query):
24
- if not query.strip():
25
- return "Please enter a valid query."
26
-
27
- res = search.invoke(query)
28
- context = "\n".join([r["content"] for r in res.get("results", [])])
29
-
30
- prompt = f"""
31
- Using the following information from web search:
32
- {context}
33
-
34
- Question: {query}
35
- Answer clearly and concisely:
36
- """
37
-
38
- response = llm.invoke(prompt)
39
- return response.content.strip()
40
-
41
- custom_css = """
42
- body {
43
- background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
44
- }
45
-
46
- .gradio-container {
47
- max-width: 900px !important;
48
- margin: auto;
49
- }
50
-
51
- #title {
52
- font-size: 36px;
53
- font-weight: 700;
54
- text-align: center;
55
- color: white;
56
- }
57
-
58
- #subtitle {
59
- text-align: center;
60
- color: #cfd8dc;
61
- margin-bottom: 20px;
62
- }
63
-
64
- .card {
65
- background: #111827;
66
- border-radius: 16px;
67
- padding: 24px;
68
- box-shadow: 0px 10px 30px rgba(0,0,0,0.4);
69
- }
70
- """
71
-
72
- with gr.Blocks(css=custom_css) as demo:
73
- gr.Markdown("<div id='title'>Nithi's Search Assistant</div>")
74
- gr.Markdown("<div id='subtitle'>Nithi's Search Agent</div>")
75
-
76
- with gr.Column(elem_classes="card"):
77
- query_input = gr.Textbox(
78
- label="Enter your question",
79
- placeholder="Enter your question",
80
- lines=2
81
- )
82
-
83
- search_btn = gr.Button("Search", variant="primary")
84
 
85
- output_box = gr.Textbox(
86
- label="AI Answer",
87
- lines=10,
88
- interactive=False
89
- )
90
 
91
- search_btn.click(
92
- fn=search_agent,
93
- inputs=query_input,
94
- outputs=output_box
95
- )
96
 
97
- demo.launch()
 
 
 
 
 
1
  import os
2
  import gradio as gr
3
  from langchain_groq import ChatGroq
4
+ from langchain_core.prompts import ChatPromptTemplate
5
+
6
+ system_prompt_ai_teacher = """
7
+ You are Nimi AI, an AI Teacher at Resynclogic - Artificial Intelligence Research Institute.
8
+ Your mission is to teach AI to beginners like you're explaining it to a 10-year-old.
9
+ Use short sentences. Be friendly and encouraging.
10
+ Always ask a small follow-up question.
11
+ Always say you are “Nimi AI – AI Teacher, built at Resynclogic – Artificial Intelligence Research Institute.”
12
+ """
13
 
 
14
  groq_api_key = os.environ.get("GROQ_API_KEY")
 
15
 
 
16
  llm = ChatGroq(
17
  model_name="openai/gpt-oss-120b",
18
+ temperature=0.7,
19
  groq_api_key=groq_api_key
20
  )
21
 
22
+ prompt = ChatPromptTemplate.from_messages([
23
+ ("system", system_prompt_ai_teacher),
24
+ ("human", "{user_input}")
25
+ ])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
27
+ chain = prompt | llm
 
 
 
 
28
 
29
+ def predict(message, history):
30
+ response = chain.invoke({"user_input": message})
31
+ return response.content
 
 
32
 
33
+ gr.ChatInterface(
34
+ predict,
35
+ title="NITHI'S CHATBOT – Nimi AI 🤖📘",
36
+ description="Beginner-friendly AI teacher. Ask anything about AI!"
37
+ ).launch()