Emperor555 Claude commited on
Commit
4ee79f3
Β·
1 Parent(s): 9aed552

Add MCP Tools Used section to UI

Browse files

Shows which tools/services were used for each explanation:
- DuckDuckGo Search (web research)
- Nebius LLM (persona transformation)
- ElevenLabs TTS (when audio enabled)

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (2) hide show
  1. app.py +28 -4
  2. src/agent.py +7 -0
app.py CHANGED
@@ -32,10 +32,21 @@ def format_sources(sources: list[dict]) -> str:
32
  return md
33
 
34
 
 
 
 
 
 
 
 
 
 
 
 
35
  def explain_topic(topic: str, persona_name: str, audience: str = "", generate_audio: bool = False, progress=gr.Progress()):
36
  """Main function to explain a topic in a persona's voice.
37
 
38
- Returns: (explanation_text, audio_path, sources_md, steps_md)
39
  """
40
  if not topic.strip():
41
  return (
@@ -43,6 +54,7 @@ def explain_topic(topic: str, persona_name: str, audience: str = "", generate_au
43
  None,
44
  "",
45
  "❌ No topic provided",
 
46
  )
47
 
48
  if not persona_name:
@@ -52,6 +64,7 @@ def explain_topic(topic: str, persona_name: str, audience: str = "", generate_au
52
  explanation = ""
53
  sources = []
54
  voice_id = None
 
55
 
56
  # Run the agent pipeline
57
  progress(0, desc="Starting...")
@@ -74,6 +87,7 @@ def explain_topic(topic: str, persona_name: str, audience: str = "", generate_au
74
  explanation = update["explanation"]
75
  sources = update.get("sources", sources)
76
  voice_id = update["voice_id"]
 
77
  progress(0.8, desc="Explanation ready!")
78
 
79
  # Format the steps log
@@ -89,6 +103,8 @@ def explain_topic(topic: str, persona_name: str, audience: str = "", generate_au
89
  with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as f:
90
  f.write(audio_bytes)
91
  audio_path = f.name
 
 
92
  progress(1.0, desc="Done!")
93
  except Exception as e:
94
  steps_log.append(f"**⚠️ Audio generation failed**\n{str(e)}")
@@ -100,7 +116,10 @@ def explain_topic(topic: str, persona_name: str, audience: str = "", generate_au
100
  # Format sources
101
  sources_md = format_sources(sources)
102
 
103
- return explanation, audio_path, sources_md, steps_md
 
 
 
104
 
105
 
106
  # Build the Gradio interface
@@ -174,6 +193,11 @@ def create_app():
174
  autoplay=False,
175
  )
176
 
 
 
 
 
 
177
  with gr.Row():
178
  with gr.Column():
179
  with gr.Accordion("πŸ” Sources", open=False):
@@ -218,14 +242,14 @@ def create_app():
218
  explain_btn.click(
219
  fn=process_and_explain,
220
  inputs=[topic_input, persona_dropdown, audio_checkbox, audience_input],
221
- outputs=[explanation_output, audio_output, sources_output, steps_output],
222
  )
223
 
224
  # Also trigger on Enter key in topic input
225
  topic_input.submit(
226
  fn=process_and_explain,
227
  inputs=[topic_input, persona_dropdown, audio_checkbox, audience_input],
228
- outputs=[explanation_output, audio_output, sources_output, steps_output],
229
  )
230
 
231
  return app
 
32
  return md
33
 
34
 
35
+ def format_mcp_tools(tools: list[dict]) -> str:
36
+ """Format MCP tools used as markdown."""
37
+ if not tools:
38
+ return "*No tools used*"
39
+
40
+ md = "**Tools & Services Used:**\n\n"
41
+ for tool in tools:
42
+ md += f"{tool['icon']} **{tool['name']}** - {tool['desc']}\n\n"
43
+ return md
44
+
45
+
46
  def explain_topic(topic: str, persona_name: str, audience: str = "", generate_audio: bool = False, progress=gr.Progress()):
47
  """Main function to explain a topic in a persona's voice.
48
 
49
+ Returns: (explanation_text, audio_path, sources_md, steps_md, mcp_md)
50
  """
51
  if not topic.strip():
52
  return (
 
54
  None,
55
  "",
56
  "❌ No topic provided",
57
+ "",
58
  )
59
 
60
  if not persona_name:
 
64
  explanation = ""
65
  sources = []
66
  voice_id = None
67
+ mcp_tools = []
68
 
69
  # Run the agent pipeline
70
  progress(0, desc="Starting...")
 
87
  explanation = update["explanation"]
88
  sources = update.get("sources", sources)
89
  voice_id = update["voice_id"]
90
+ mcp_tools = update.get("mcp_tools", [])
91
  progress(0.8, desc="Explanation ready!")
92
 
93
  # Format the steps log
 
103
  with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as f:
104
  f.write(audio_bytes)
105
  audio_path = f.name
106
+ # Add ElevenLabs to MCP tools
107
+ mcp_tools.append({"name": "ElevenLabs TTS", "icon": "πŸ”Š", "desc": "Text-to-speech audio generation"})
108
  progress(1.0, desc="Done!")
109
  except Exception as e:
110
  steps_log.append(f"**⚠️ Audio generation failed**\n{str(e)}")
 
116
  # Format sources
117
  sources_md = format_sources(sources)
118
 
119
+ # Format MCP tools
120
+ mcp_md = format_mcp_tools(mcp_tools)
121
+
122
+ return explanation, audio_path, sources_md, steps_md, mcp_md
123
 
124
 
125
  # Build the Gradio interface
 
193
  autoplay=False,
194
  )
195
 
196
+ with gr.Row():
197
+ with gr.Column():
198
+ with gr.Accordion("πŸ”Œ MCP Tools Used", open=True):
199
+ mcp_output = gr.Markdown("")
200
+
201
  with gr.Row():
202
  with gr.Column():
203
  with gr.Accordion("πŸ” Sources", open=False):
 
242
  explain_btn.click(
243
  fn=process_and_explain,
244
  inputs=[topic_input, persona_dropdown, audio_checkbox, audience_input],
245
+ outputs=[explanation_output, audio_output, sources_output, steps_output, mcp_output],
246
  )
247
 
248
  # Also trigger on Enter key in topic input
249
  topic_input.submit(
250
  fn=process_and_explain,
251
  inputs=[topic_input, persona_dropdown, audio_checkbox, audience_input],
252
+ outputs=[explanation_output, audio_output, sources_output, steps_output, mcp_output],
253
  )
254
 
255
  return app
src/agent.py CHANGED
@@ -263,6 +263,12 @@ Now explain "{topic}" in your unique {persona_name} voice and style. Make it fun
263
 
264
  explanation = call_llm(messages)
265
 
 
 
 
 
 
 
266
  yield {
267
  "type": "result",
268
  "explanation": explanation,
@@ -270,4 +276,5 @@ Now explain "{topic}" in your unique {persona_name} voice and style. Make it fun
270
  "persona": persona_name,
271
  "persona_emoji": persona["emoji"],
272
  "voice_id": persona["voice_id"],
 
273
  }
 
263
 
264
  explanation = call_llm(messages)
265
 
266
+ # Track MCP tools used
267
+ mcp_tools = [
268
+ {"name": "DuckDuckGo Search", "icon": "πŸ”", "desc": "Web search for topic research"},
269
+ {"name": "Nebius LLM", "icon": "🧠", "desc": "Llama 3.3 70B for persona transformation"},
270
+ ]
271
+
272
  yield {
273
  "type": "result",
274
  "explanation": explanation,
 
276
  "persona": persona_name,
277
  "persona_emoji": persona["emoji"],
278
  "voice_id": persona["voice_id"],
279
+ "mcp_tools": mcp_tools,
280
  }