Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -53,7 +53,7 @@ RESPONSE FORMAT:
|
|
53 |
|
54 |
Remember: Your goal is to be the most reliable, up-to-date source of information possible."""
|
55 |
|
56 |
-
def query_compound_model(self, query, model, temperature=0.7):
|
57 |
"""Query the compound model and return response with tool execution info"""
|
58 |
if not self.client:
|
59 |
return "❌ Please set a valid API key first.", None, None
|
@@ -61,11 +61,14 @@ Remember: Your goal is to be the most reliable, up-to-date source of information
|
|
61 |
try:
|
62 |
start_time = time.time()
|
63 |
|
|
|
|
|
|
|
64 |
chat_completion = self.client.chat.completions.create(
|
65 |
messages=[
|
66 |
{
|
67 |
"role": "system",
|
68 |
-
"content":
|
69 |
},
|
70 |
{
|
71 |
"role": "user",
|
@@ -74,7 +77,7 @@ Remember: Your goal is to be the most reliable, up-to-date source of information
|
|
74 |
],
|
75 |
model=model,
|
76 |
temperature=temperature,
|
77 |
-
max_tokens=
|
78 |
)
|
79 |
|
80 |
end_time = time.time()
|
@@ -83,7 +86,7 @@ Remember: Your goal is to be the most reliable, up-to-date source of information
|
|
83 |
# Extract response
|
84 |
response_content = chat_completion.choices[0].message.content
|
85 |
|
86 |
-
# Check for executed tools
|
87 |
executed_tools = getattr(chat_completion.choices[0].message, 'executed_tools', None)
|
88 |
|
89 |
# Format tool execution info
|
@@ -95,21 +98,36 @@ Remember: Your goal is to be the most reliable, up-to-date source of information
|
|
95 |
return f"❌ Error querying model: {str(e)}", None, None
|
96 |
|
97 |
def format_tool_info(self, executed_tools):
|
98 |
-
"""Format executed tools information for display"""
|
99 |
if not executed_tools:
|
100 |
return "🔍 **Tools Used:** None (Used existing knowledge)"
|
101 |
|
102 |
tool_info = "🔍 **Tools Used:**\n"
|
103 |
for i, tool in enumerate(executed_tools, 1):
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
return tool_info
|
115 |
|
@@ -159,10 +177,193 @@ Remember: Your goal is to be the most reliable, up-to-date source of information
|
|
159 |
"Verify recent claims about electric vehicle sales"
|
160 |
]
|
161 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
|
163 |
def create_interface():
|
164 |
fact_checker = RealTimeFactChecker()
|
165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
def validate_api_key(api_key):
|
167 |
if not api_key or api_key.strip() == "":
|
168 |
return "❌ Please enter a valid API key", False
|
@@ -183,19 +384,10 @@ def create_interface():
|
|
183 |
if not success:
|
184 |
return message, "", ""
|
185 |
|
186 |
-
# Use custom system prompt if provided
|
187 |
-
if system_prompt and system_prompt.strip():
|
188 |
-
original_prompt = fact_checker.get_system_prompt
|
189 |
-
fact_checker.get_system_prompt = lambda: system_prompt.strip()
|
190 |
-
|
191 |
response, tool_info, response_time = fact_checker.query_compound_model(
|
192 |
-
query.strip(), model, temperature
|
193 |
)
|
194 |
|
195 |
-
# Restore original system prompt function
|
196 |
-
if system_prompt and system_prompt.strip():
|
197 |
-
fact_checker.get_system_prompt = original_prompt
|
198 |
-
|
199 |
# Format response with timestamp
|
200 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
201 |
formatted_response = f"**Query:** {query}\n\n**Response:**\n{response}\n\n---\n*Generated at {timestamp} in {response_time}s*"
|
@@ -208,21 +400,25 @@ def create_interface():
|
|
208 |
def load_example(example_text):
|
209 |
return example_text
|
210 |
|
|
|
|
|
|
|
211 |
# Create the Gradio interface
|
212 |
-
with gr.Blocks(title="Real-time Fact Checker & News Agent",
|
213 |
-
gr.Markdown("""
|
214 |
-
# 🔍 Real-time Fact Checker & News Agent
|
215 |
-
|
216 |
-
**Powered by Groq's Compound Models with Built-in Web Search**
|
217 |
|
218 |
-
|
219 |
-
|
|
|
|
|
|
|
|
|
220 |
""")
|
221 |
|
222 |
with gr.Row():
|
223 |
with gr.Column(scale=2):
|
224 |
# API Key section
|
225 |
with gr.Group():
|
|
|
226 |
gr.Markdown("### 🔑 API Configuration")
|
227 |
api_key_input = gr.Textbox(
|
228 |
label="Groq API Key",
|
@@ -236,26 +432,57 @@ def create_interface():
|
|
236 |
interactive=False
|
237 |
)
|
238 |
validate_btn = gr.Button("Validate API Key", variant="secondary")
|
|
|
239 |
|
240 |
# Advanced options
|
241 |
with gr.Group():
|
|
|
242 |
gr.Markdown("### ⚙️ Advanced Options")
|
243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
system_prompt_input = gr.Textbox(
|
245 |
label="System Prompt",
|
246 |
value=fact_checker.get_system_prompt(),
|
247 |
lines=8,
|
248 |
-
info="Customize how the AI behaves and responds"
|
|
|
249 |
)
|
250 |
reset_prompt_btn = gr.Button("Reset to Default", variant="secondary", size="sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
|
252 |
# Query section
|
253 |
with gr.Group():
|
|
|
254 |
gr.Markdown("### 💭 Your Query")
|
255 |
query_input = gr.Textbox(
|
256 |
label="Ask anything that requires real-time information",
|
257 |
placeholder="e.g., What are the latest AI developments today?",
|
258 |
-
lines=
|
259 |
)
|
260 |
|
261 |
with gr.Row():
|
@@ -276,25 +503,69 @@ def create_interface():
|
|
276 |
|
277 |
submit_btn = gr.Button("🔍 Get Real-time Information", variant="primary", size="lg")
|
278 |
clear_btn = gr.Button("Clear", variant="secondary")
|
|
|
279 |
|
280 |
with gr.Column(scale=1):
|
281 |
-
# Example queries
|
282 |
with gr.Group():
|
|
|
283 |
gr.Markdown("### 📝 Example Queries")
|
284 |
gr.Markdown("Click any example to load it:")
|
285 |
|
286 |
examples = fact_checker.get_example_queries()
|
287 |
-
|
288 |
-
|
289 |
-
for query in
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
example_btn = gr.Button(query, variant="secondary", size="sm")
|
291 |
example_btn.click(
|
292 |
-
fn=
|
293 |
-
inputs=[gr.State(query)],
|
294 |
outputs=[query_input]
|
295 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
# Results section
|
|
|
298 |
gr.Markdown("### 📊 Results")
|
299 |
|
300 |
with gr.Row():
|
@@ -315,6 +586,7 @@ def create_interface():
|
|
315 |
value="",
|
316 |
interactive=False
|
317 |
)
|
|
|
318 |
|
319 |
# Event handlers
|
320 |
validate_btn.click(
|
@@ -340,17 +612,24 @@ def create_interface():
|
|
340 |
)
|
341 |
|
342 |
# Footer
|
343 |
-
gr.
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
""")
|
355 |
|
356 |
return demo
|
|
|
53 |
|
54 |
Remember: Your goal is to be the most reliable, up-to-date source of information possible."""
|
55 |
|
56 |
+
def query_compound_model(self, query, model, temperature=0.7, custom_system_prompt=None):
|
57 |
"""Query the compound model and return response with tool execution info"""
|
58 |
if not self.client:
|
59 |
return "❌ Please set a valid API key first.", None, None
|
|
|
61 |
try:
|
62 |
start_time = time.time()
|
63 |
|
64 |
+
# Use custom system prompt if provided
|
65 |
+
system_prompt = custom_system_prompt if custom_system_prompt else self.get_system_prompt()
|
66 |
+
|
67 |
chat_completion = self.client.chat.completions.create(
|
68 |
messages=[
|
69 |
{
|
70 |
"role": "system",
|
71 |
+
"content": system_prompt
|
72 |
},
|
73 |
{
|
74 |
"role": "user",
|
|
|
77 |
],
|
78 |
model=model,
|
79 |
temperature=temperature,
|
80 |
+
max_tokens=1500
|
81 |
)
|
82 |
|
83 |
end_time = time.time()
|
|
|
86 |
# Extract response
|
87 |
response_content = chat_completion.choices[0].message.content
|
88 |
|
89 |
+
# Check for executed tools - Fixed the error here
|
90 |
executed_tools = getattr(chat_completion.choices[0].message, 'executed_tools', None)
|
91 |
|
92 |
# Format tool execution info
|
|
|
98 |
return f"❌ Error querying model: {str(e)}", None, None
|
99 |
|
100 |
def format_tool_info(self, executed_tools):
|
101 |
+
"""Format executed tools information for display - FIXED"""
|
102 |
if not executed_tools:
|
103 |
return "🔍 **Tools Used:** None (Used existing knowledge)"
|
104 |
|
105 |
tool_info = "🔍 **Tools Used:**\n"
|
106 |
for i, tool in enumerate(executed_tools, 1):
|
107 |
+
try:
|
108 |
+
# Handle different tool object types
|
109 |
+
if hasattr(tool, 'name'):
|
110 |
+
tool_name = tool.name
|
111 |
+
elif hasattr(tool, 'tool_name'):
|
112 |
+
tool_name = tool.tool_name
|
113 |
+
elif isinstance(tool, dict):
|
114 |
+
tool_name = tool.get('name', 'Unknown')
|
115 |
+
else:
|
116 |
+
tool_name = str(tool)
|
117 |
+
|
118 |
+
tool_info += f"{i}. **{tool_name}**\n"
|
119 |
+
|
120 |
+
# Add tool parameters if available
|
121 |
+
if hasattr(tool, 'parameters'):
|
122 |
+
params = tool.parameters
|
123 |
+
if isinstance(params, dict):
|
124 |
+
for key, value in params.items():
|
125 |
+
tool_info += f" - {key}: {value}\n"
|
126 |
+
elif hasattr(tool, 'input'):
|
127 |
+
tool_info += f" - Input: {tool.input}\n"
|
128 |
+
|
129 |
+
except Exception as e:
|
130 |
+
tool_info += f"{i}. **Tool {i}** (Error parsing details)\n"
|
131 |
|
132 |
return tool_info
|
133 |
|
|
|
177 |
"Verify recent claims about electric vehicle sales"
|
178 |
]
|
179 |
}
|
180 |
+
|
181 |
+
def get_custom_prompt_examples(self):
|
182 |
+
"""Return custom system prompt examples"""
|
183 |
+
return {
|
184 |
+
"🎯 Fact-Checker": "You are a fact-checker. Always verify claims with multiple sources and clearly indicate confidence levels in your assessments. Use phrases like 'highly confident', 'moderately confident', or 'requires verification' when presenting information.",
|
185 |
+
|
186 |
+
"📊 News Analyst": "You are a news analyst. Focus on providing balanced, unbiased reporting with multiple perspectives on current events. Always present different viewpoints and avoid partisan language.",
|
187 |
+
|
188 |
+
"💼 Financial Advisor": "You are a financial advisor. Provide accurate market data with context about trends and implications for investors. Always include disclaimers about market risks and the importance of professional financial advice.",
|
189 |
+
|
190 |
+
"🔬 Research Assistant": "You are a research assistant specializing in scientific and technical information. Provide detailed, evidence-based responses with proper context about methodology and limitations of studies.",
|
191 |
+
|
192 |
+
"🌍 Global News Correspondent": "You are a global news correspondent. Focus on international events and their interconnections. Provide cultural context and explain how events in one region might affect others.",
|
193 |
+
|
194 |
+
"📈 Market Analyst": "You are a market analyst. Provide detailed financial analysis including technical indicators, market sentiment, and economic factors affecting price movements."
|
195 |
+
}
|
196 |
|
197 |
def create_interface():
|
198 |
fact_checker = RealTimeFactChecker()
|
199 |
|
200 |
+
# Custom CSS for beautiful styling
|
201 |
+
custom_css = """
|
202 |
+
<style>
|
203 |
+
.gradio-container {
|
204 |
+
max-width: 1400px !important;
|
205 |
+
margin: 0 auto;
|
206 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
207 |
+
min-height: 100vh;
|
208 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
209 |
+
}
|
210 |
+
|
211 |
+
.main-header {
|
212 |
+
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
|
213 |
+
color: white;
|
214 |
+
padding: 30px;
|
215 |
+
border-radius: 20px;
|
216 |
+
margin-bottom: 30px;
|
217 |
+
text-align: center;
|
218 |
+
box-shadow: 0 10px 30px rgba(0,0,0,0.3);
|
219 |
+
}
|
220 |
+
|
221 |
+
.main-header h1 {
|
222 |
+
font-size: 2.5rem;
|
223 |
+
margin: 0;
|
224 |
+
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
|
225 |
+
}
|
226 |
+
|
227 |
+
.main-header p {
|
228 |
+
font-size: 1.2rem;
|
229 |
+
margin: 10px 0 0 0;
|
230 |
+
opacity: 0.9;
|
231 |
+
}
|
232 |
+
|
233 |
+
.feature-card {
|
234 |
+
background: white;
|
235 |
+
border-radius: 15px;
|
236 |
+
padding: 25px;
|
237 |
+
margin: 20px 0;
|
238 |
+
box-shadow: 0 8px 25px rgba(0,0,0,0.1);
|
239 |
+
border: 1px solid #e1e8ed;
|
240 |
+
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
241 |
+
}
|
242 |
+
|
243 |
+
.feature-card:hover {
|
244 |
+
transform: translateY(-5px);
|
245 |
+
box-shadow: 0 15px 40px rgba(0,0,0,0.2);
|
246 |
+
}
|
247 |
+
|
248 |
+
.example-grid {
|
249 |
+
display: grid;
|
250 |
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
251 |
+
gap: 15px;
|
252 |
+
margin-top: 20px;
|
253 |
+
}
|
254 |
+
|
255 |
+
.example-category {
|
256 |
+
background: #f8f9fa;
|
257 |
+
border-radius: 10px;
|
258 |
+
padding: 15px;
|
259 |
+
border-left: 4px solid #667eea;
|
260 |
+
}
|
261 |
+
|
262 |
+
.example-category h4 {
|
263 |
+
margin: 0 0 10px 0;
|
264 |
+
color: #2d3748;
|
265 |
+
font-weight: 600;
|
266 |
+
}
|
267 |
+
|
268 |
+
.status-success {
|
269 |
+
background: linear-gradient(135deg, #48bb78 0%, #38a169 100%);
|
270 |
+
color: white;
|
271 |
+
padding: 10px 15px;
|
272 |
+
border-radius: 8px;
|
273 |
+
font-weight: 500;
|
274 |
+
}
|
275 |
+
|
276 |
+
.status-warning {
|
277 |
+
background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%);
|
278 |
+
color: white;
|
279 |
+
padding: 10px 15px;
|
280 |
+
border-radius: 8px;
|
281 |
+
font-weight: 500;
|
282 |
+
}
|
283 |
+
|
284 |
+
.status-error {
|
285 |
+
background: linear-gradient(135deg, #f56565 0%, #e53e3e 100%);
|
286 |
+
color: white;
|
287 |
+
padding: 10px 15px;
|
288 |
+
border-radius: 8px;
|
289 |
+
font-weight: 500;
|
290 |
+
}
|
291 |
+
|
292 |
+
.results-section {
|
293 |
+
background: white;
|
294 |
+
border-radius: 15px;
|
295 |
+
padding: 30px;
|
296 |
+
margin: 30px 0;
|
297 |
+
box-shadow: 0 8px 25px rgba(0,0,0,0.1);
|
298 |
+
}
|
299 |
+
|
300 |
+
.tool-info {
|
301 |
+
background: #f7fafc;
|
302 |
+
border-left: 4px solid #4299e1;
|
303 |
+
padding: 15px;
|
304 |
+
border-radius: 8px;
|
305 |
+
margin: 15px 0;
|
306 |
+
}
|
307 |
+
|
308 |
+
.performance-badge {
|
309 |
+
background: linear-gradient(135deg, #38b2ac 0%, #319795 100%);
|
310 |
+
color: white;
|
311 |
+
padding: 8px 15px;
|
312 |
+
border-radius: 20px;
|
313 |
+
font-weight: 500;
|
314 |
+
display: inline-block;
|
315 |
+
margin: 10px 0;
|
316 |
+
}
|
317 |
+
|
318 |
+
.footer-section {
|
319 |
+
background: #2d3748;
|
320 |
+
color: white;
|
321 |
+
padding: 30px;
|
322 |
+
border-radius: 15px;
|
323 |
+
margin-top: 30px;
|
324 |
+
text-align: center;
|
325 |
+
}
|
326 |
+
|
327 |
+
.footer-section a {
|
328 |
+
color: #63b3ed;
|
329 |
+
text-decoration: none;
|
330 |
+
font-weight: 500;
|
331 |
+
}
|
332 |
+
|
333 |
+
.footer-section a:hover {
|
334 |
+
color: #90cdf4;
|
335 |
+
text-decoration: underline;
|
336 |
+
}
|
337 |
+
|
338 |
+
.prompt-example {
|
339 |
+
background: #ebf8ff;
|
340 |
+
border: 1px solid #bee3f8;
|
341 |
+
border-radius: 8px;
|
342 |
+
padding: 12px;
|
343 |
+
margin: 8px 0;
|
344 |
+
cursor: pointer;
|
345 |
+
transition: all 0.3s ease;
|
346 |
+
}
|
347 |
+
|
348 |
+
.prompt-example:hover {
|
349 |
+
background: #bee3f8;
|
350 |
+
transform: translateX(5px);
|
351 |
+
}
|
352 |
+
|
353 |
+
.prompt-example-title {
|
354 |
+
font-weight: 600;
|
355 |
+
color: #2b6cb0;
|
356 |
+
margin-bottom: 5px;
|
357 |
+
}
|
358 |
+
|
359 |
+
.prompt-example-text {
|
360 |
+
font-size: 0.9rem;
|
361 |
+
color: #4a5568;
|
362 |
+
line-height: 1.4;
|
363 |
+
}
|
364 |
+
</style>
|
365 |
+
"""
|
366 |
+
|
367 |
def validate_api_key(api_key):
|
368 |
if not api_key or api_key.strip() == "":
|
369 |
return "❌ Please enter a valid API key", False
|
|
|
384 |
if not success:
|
385 |
return message, "", ""
|
386 |
|
|
|
|
|
|
|
|
|
|
|
387 |
response, tool_info, response_time = fact_checker.query_compound_model(
|
388 |
+
query.strip(), model, temperature, system_prompt.strip() if system_prompt else None
|
389 |
)
|
390 |
|
|
|
|
|
|
|
|
|
391 |
# Format response with timestamp
|
392 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
393 |
formatted_response = f"**Query:** {query}\n\n**Response:**\n{response}\n\n---\n*Generated at {timestamp} in {response_time}s*"
|
|
|
400 |
def load_example(example_text):
|
401 |
return example_text
|
402 |
|
403 |
+
def load_custom_prompt(prompt_text):
|
404 |
+
return prompt_text
|
405 |
+
|
406 |
# Create the Gradio interface
|
407 |
+
with gr.Blocks(title="Real-time Fact Checker & News Agent", css=custom_css) as demo:
|
|
|
|
|
|
|
|
|
408 |
|
409 |
+
# Header
|
410 |
+
gr.HTML("""
|
411 |
+
<div class="main-header">
|
412 |
+
<h1>🔍 Real-time Fact Checker & News Agent</h1>
|
413 |
+
<p>Powered by Groq's Compound Models with Built-in Web Search</p>
|
414 |
+
</div>
|
415 |
""")
|
416 |
|
417 |
with gr.Row():
|
418 |
with gr.Column(scale=2):
|
419 |
# API Key section
|
420 |
with gr.Group():
|
421 |
+
gr.HTML('<div class="feature-card">')
|
422 |
gr.Markdown("### 🔑 API Configuration")
|
423 |
api_key_input = gr.Textbox(
|
424 |
label="Groq API Key",
|
|
|
432 |
interactive=False
|
433 |
)
|
434 |
validate_btn = gr.Button("Validate API Key", variant="secondary")
|
435 |
+
gr.HTML('</div>')
|
436 |
|
437 |
# Advanced options
|
438 |
with gr.Group():
|
439 |
+
gr.HTML('<div class="feature-card">')
|
440 |
gr.Markdown("### ⚙️ Advanced Options")
|
441 |
+
|
442 |
+
# Custom System Prompt Examples
|
443 |
+
with gr.Accordion("📝 System Prompt Examples (Click to view)", open=False):
|
444 |
+
gr.Markdown("**Click any example to load it as your system prompt:**")
|
445 |
+
|
446 |
+
custom_prompts = fact_checker.get_custom_prompt_examples()
|
447 |
+
for title, prompt in custom_prompts.items():
|
448 |
+
with gr.Row():
|
449 |
+
gr.HTML(f"""
|
450 |
+
<div class="prompt-example" onclick="document.getElementById('system_prompt_input').value = '{prompt}'">
|
451 |
+
<div class="prompt-example-title">{title}</div>
|
452 |
+
<div class="prompt-example-text">{prompt[:100]}...</div>
|
453 |
+
</div>
|
454 |
+
""")
|
455 |
+
|
456 |
+
with gr.Accordion("🔧 System Prompt (Click to customize)", open=False):
|
457 |
system_prompt_input = gr.Textbox(
|
458 |
label="System Prompt",
|
459 |
value=fact_checker.get_system_prompt(),
|
460 |
lines=8,
|
461 |
+
info="Customize how the AI behaves and responds",
|
462 |
+
elem_id="system_prompt_input"
|
463 |
)
|
464 |
reset_prompt_btn = gr.Button("Reset to Default", variant="secondary", size="sm")
|
465 |
+
|
466 |
+
# Add buttons for each custom prompt
|
467 |
+
gr.Markdown("**Quick Load Custom Prompts:**")
|
468 |
+
custom_prompts = fact_checker.get_custom_prompt_examples()
|
469 |
+
for title, prompt in custom_prompts.items():
|
470 |
+
prompt_btn = gr.Button(title, variant="secondary", size="sm")
|
471 |
+
prompt_btn.click(
|
472 |
+
fn=lambda p=prompt: p,
|
473 |
+
outputs=[system_prompt_input]
|
474 |
+
)
|
475 |
+
|
476 |
+
gr.HTML('</div>')
|
477 |
|
478 |
# Query section
|
479 |
with gr.Group():
|
480 |
+
gr.HTML('<div class="feature-card">')
|
481 |
gr.Markdown("### 💭 Your Query")
|
482 |
query_input = gr.Textbox(
|
483 |
label="Ask anything that requires real-time information",
|
484 |
placeholder="e.g., What are the latest AI developments today?",
|
485 |
+
lines=4
|
486 |
)
|
487 |
|
488 |
with gr.Row():
|
|
|
503 |
|
504 |
submit_btn = gr.Button("🔍 Get Real-time Information", variant="primary", size="lg")
|
505 |
clear_btn = gr.Button("Clear", variant="secondary")
|
506 |
+
gr.HTML('</div>')
|
507 |
|
508 |
with gr.Column(scale=1):
|
509 |
+
# Example queries with tabs
|
510 |
with gr.Group():
|
511 |
+
gr.HTML('<div class="feature-card">')
|
512 |
gr.Markdown("### 📝 Example Queries")
|
513 |
gr.Markdown("Click any example to load it:")
|
514 |
|
515 |
examples = fact_checker.get_example_queries()
|
516 |
+
|
517 |
+
with gr.Accordion("📰 Latest News", open=True):
|
518 |
+
for query in examples["📰 Latest News"]:
|
519 |
+
example_btn = gr.Button(query, variant="secondary", size="sm")
|
520 |
+
example_btn.click(
|
521 |
+
fn=lambda q=query: q,
|
522 |
+
outputs=[query_input]
|
523 |
+
)
|
524 |
+
|
525 |
+
with gr.Accordion("💰 Financial Data", open=False):
|
526 |
+
for query in examples["💰 Financial Data"]:
|
527 |
+
example_btn = gr.Button(query, variant="secondary", size="sm")
|
528 |
+
example_btn.click(
|
529 |
+
fn=lambda q=query: q,
|
530 |
+
outputs=[query_input]
|
531 |
+
)
|
532 |
+
|
533 |
+
with gr.Accordion("🌤️ Weather Updates", open=False):
|
534 |
+
for query in examples["🌤️ Weather Updates"]:
|
535 |
example_btn = gr.Button(query, variant="secondary", size="sm")
|
536 |
example_btn.click(
|
537 |
+
fn=lambda q=query: q,
|
|
|
538 |
outputs=[query_input]
|
539 |
)
|
540 |
+
|
541 |
+
with gr.Accordion("🔬 Science & Technology", open=False):
|
542 |
+
for query in examples["🔬 Science & Technology"]:
|
543 |
+
example_btn = gr.Button(query, variant="secondary", size="sm")
|
544 |
+
example_btn.click(
|
545 |
+
fn=lambda q=query: q,
|
546 |
+
outputs=[query_input]
|
547 |
+
)
|
548 |
+
|
549 |
+
with gr.Accordion("🏆 Sports & Entertainment", open=False):
|
550 |
+
for query in examples["🏆 Sports & Entertainment"]:
|
551 |
+
example_btn = gr.Button(query, variant="secondary", size="sm")
|
552 |
+
example_btn.click(
|
553 |
+
fn=lambda q=query: q,
|
554 |
+
outputs=[query_input]
|
555 |
+
)
|
556 |
+
|
557 |
+
with gr.Accordion("🔍 Fact Checking", open=False):
|
558 |
+
for query in examples["🔍 Fact Checking"]:
|
559 |
+
example_btn = gr.Button(query, variant="secondary", size="sm")
|
560 |
+
example_btn.click(
|
561 |
+
fn=lambda q=query: q,
|
562 |
+
outputs=[query_input]
|
563 |
+
)
|
564 |
+
|
565 |
+
gr.HTML('</div>')
|
566 |
|
567 |
# Results section
|
568 |
+
gr.HTML('<div class="results-section">')
|
569 |
gr.Markdown("### 📊 Results")
|
570 |
|
571 |
with gr.Row():
|
|
|
586 |
value="",
|
587 |
interactive=False
|
588 |
)
|
589 |
+
gr.HTML('</div>')
|
590 |
|
591 |
# Event handlers
|
592 |
validate_btn.click(
|
|
|
612 |
)
|
613 |
|
614 |
# Footer
|
615 |
+
gr.HTML("""
|
616 |
+
<div class="footer-section">
|
617 |
+
<h3>🔗 Useful Links</h3>
|
618 |
+
<p>
|
619 |
+
<a href="https://console.groq.com/" target="_blank">Groq Console</a> - Get your free API key<br>
|
620 |
+
<a href="https://console.groq.com/docs/quickstart" target="_blank">Groq Documentation</a> - Learn more about Groq models<br>
|
621 |
+
<a href="https://console.groq.com/docs/models" target="_blank">Compound Models Info</a> - Details about compound models
|
622 |
+
</p>
|
623 |
+
|
624 |
+
<h3>💡 Tips</h3>
|
625 |
+
<ul style="text-align: left; display: inline-block;">
|
626 |
+
<li>The compound models automatically use web search when real-time information is needed</li>
|
627 |
+
<li>Try different temperature settings: 0.1 for factual queries, 0.7-0.9 for creative questions</li>
|
628 |
+
<li>compound-beta is more capable but slower, compound-beta-mini is faster but less capable</li>
|
629 |
+
<li>Use custom system prompts to specialize the AI for different types of queries</li>
|
630 |
+
<li>Check the Tool Execution Info to see when web search was used</li>
|
631 |
+
</ul>
|
632 |
+
</div>
|
633 |
""")
|
634 |
|
635 |
return demo
|