NithikaShree commited on
Commit
f3c9c7f
·
verified ·
1 Parent(s): 1f4e3e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -25
app.py CHANGED
@@ -3,21 +3,28 @@ import gradio as gr
3
  from langchain_groq import ChatGroq
4
  from langchain_tavily import TavilySearch
5
 
6
- # Load API keys from Hugging Face Secrets
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 google_style_search(query):
@@ -28,32 +35,36 @@ def google_style_search(query):
28
  context = "\n".join([r["content"] for r in res.get("results", [])])
29
 
30
  prompt = f"""
31
- Using the following web search information:
32
- {context}
 
33
 
34
- Question: {query}
35
- Answer in a clear, user-friendly manner:
36
- """
37
 
38
  response = llm.invoke(prompt)
39
  return response.content.strip()
40
 
41
  google_css = """
 
 
42
  body {
43
  background-color: #ffffff;
44
- font-family: Arial, sans-serif;
45
  }
46
 
47
  .gradio-container {
48
- max-width: 800px !important;
49
  margin-top: 60px;
50
  }
51
 
52
  #logo {
53
- font-size: 48px;
54
  font-weight: 700;
55
  text-align: center;
56
- margin-bottom: 30px;
 
57
  }
58
 
59
  #logo span:nth-child(1) { color: #4285F4; }
@@ -62,27 +73,68 @@ body {
62
  #logo span:nth-child(4) { color: #4285F4; }
63
  #logo span:nth-child(5) { color: #0F9D58; }
64
  #logo span:nth-child(6) { color: #DB4437; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  """
66
 
67
  with gr.Blocks(css=google_css) as demo:
68
- gr.Markdown("""
69
- <div id="logo">
70
- <span>G</span><span>o</span><span>o</span><span>g</span><span>l</span><span>e</span>
71
- </div>
72
- """)
 
 
 
 
73
 
74
  query_input = gr.Textbox(
75
  placeholder="Search anything...",
76
  lines=1,
77
- show_label=False
 
78
  )
79
 
80
- search_button = gr.Button("Search")
 
 
 
81
 
82
  answer_output = gr.Textbox(
83
  label="Search Result",
84
  lines=12,
85
- interactive=False
 
86
  )
87
 
88
  search_button.click(
 
3
  from langchain_groq import ChatGroq
4
  from langchain_tavily import TavilySearch
5
 
6
+ # =========================
7
+ # Environment Variables
8
+ # =========================
9
+ # Set these in Hugging Face Spaces → Settings → Secrets
10
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
11
+ TAVILY_API_KEY = os.getenv("TAVILY_API_KEY")
12
+
13
+ if not GROQ_API_KEY or not TAVILY_API_KEY:
14
+ raise ValueError("Please set GROQ_API_KEY and TAVILY_API_KEY in Hugging Face Secrets")
15
+
16
+ # =========================
17
+ # LLM & Search Setup
18
+ # =========================
19
  llm = ChatGroq(
20
  model_name="openai/gpt-oss-120b",
21
  temperature=0,
22
+ groq_api_key=GROQ_API_KEY
23
  )
24
 
 
25
  search = TavilySearch(
26
  max_results=5,
27
+ tavily_api_key=TAVILY_API_KEY
28
  )
29
 
30
  def google_style_search(query):
 
35
  context = "\n".join([r["content"] for r in res.get("results", [])])
36
 
37
  prompt = f"""
38
+ Using the following web search information:
39
+
40
+ {context}
41
 
42
+ Question: {query}
43
+ Answer in a clear, user-friendly, Google-style summary:
44
+ """
45
 
46
  response = llm.invoke(prompt)
47
  return response.content.strip()
48
 
49
  google_css = """
50
+ @import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&family=Inter:wght@400;500;700&display=swap');
51
+
52
  body {
53
  background-color: #ffffff;
54
+ font-family: 'Google Sans', 'Inter', Arial, sans-serif;
55
  }
56
 
57
  .gradio-container {
58
+ max-width: 850px !important;
59
  margin-top: 60px;
60
  }
61
 
62
  #logo {
63
+ font-size: 52px;
64
  font-weight: 700;
65
  text-align: center;
66
+ margin-bottom: 35px;
67
+ letter-spacing: -1px;
68
  }
69
 
70
  #logo span:nth-child(1) { color: #4285F4; }
 
73
  #logo span:nth-child(4) { color: #4285F4; }
74
  #logo span:nth-child(5) { color: #0F9D58; }
75
  #logo span:nth-child(6) { color: #DB4437; }
76
+
77
+ .search-box textarea {
78
+ border-radius: 24px !important;
79
+ border: 1px solid #dfe1e5 !important;
80
+ padding: 14px 20px !important;
81
+ font-size: 16px !important;
82
+ }
83
+
84
+ .search-box textarea:focus {
85
+ box-shadow: 0 1px 6px rgba(32,33,36,.28);
86
+ border-color: transparent !important;
87
+ }
88
+
89
+ .search-btn button {
90
+ border-radius: 6px !important;
91
+ background-color: #f8f9fa !important;
92
+ color: #202124 !important;
93
+ border: 1px solid #f8f9fa !important;
94
+ font-weight: 500;
95
+ }
96
+
97
+ .search-btn button:hover {
98
+ border: 1px solid #dadce0 !important;
99
+ background-color: #f8f9fa !important;
100
+ }
101
+
102
+ .answer-box textarea {
103
+ border-radius: 12px !important;
104
+ background: #f8f9fa !important;
105
+ font-size: 15px !important;
106
+ line-height: 1.6;
107
+ }
108
  """
109
 
110
  with gr.Blocks(css=google_css) as demo:
111
+
112
+ gr.Markdown(
113
+ """
114
+ <div id="logo">
115
+ <span>G</span><span>o</span><span>o</span><span>g</span><span>l</span><span>e</span>
116
+ </div>
117
+ """,
118
+ elem_id="logo"
119
+ )
120
 
121
  query_input = gr.Textbox(
122
  placeholder="Search anything...",
123
  lines=1,
124
+ show_label=False,
125
+ elem_classes="search-box"
126
  )
127
 
128
+ search_button = gr.Button(
129
+ "Search",
130
+ elem_classes="search-btn"
131
+ )
132
 
133
  answer_output = gr.Textbox(
134
  label="Search Result",
135
  lines=12,
136
+ interactive=False,
137
+ elem_classes="answer-box"
138
  )
139
 
140
  search_button.click(