NithikaShree commited on
Commit
485f344
·
verified ·
1 Parent(s): f153a1a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +97 -0
app.py ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()