cyberandy commited on
Commit
ad0839d
·
1 Parent(s): 7e6371a
Files changed (1) hide show
  1. app.py +52 -23
app.py CHANGED
@@ -247,26 +247,35 @@ def create_gradio_interface():
247
  def analyze(text):
248
  results = analyzer.analyze_content(text)
249
 
250
- output = "Content Analysis Results\n\n"
251
 
252
- output += "Category Scores:\n"
253
  for category, features in results["categories"].items():
254
  if features:
255
  avg_score = np.mean([f["activation_score"] for f in features])
256
- output += f"{category.title()}: {avg_score:.2f}\n"
257
 
258
- output += "\nFeature Details:\n"
259
  for feature_id, feature in results["features"].items():
260
- output += f"\n{feature['name']}:\n"
261
- output += f"Score: {feature['activation_score']:.2f}\n"
262
- output += f"Interpretation: {feature['interpretation']}\n"
 
 
263
 
264
  if results["recommendations"]:
265
- output += "\nRecommendations:\n"
266
  for rec in results["recommendations"]:
267
  output += f"- {rec}\n"
268
 
269
- return output
 
 
 
 
 
 
 
270
 
271
  with gr.Blocks(
272
  theme=gr.themes.Default(
@@ -282,23 +291,43 @@ def create_gradio_interface():
282
  )
283
 
284
  with gr.Row():
285
- input_text = gr.Textbox(
286
- lines=5,
287
- placeholder="Enter your marketing content here...",
288
- label="Marketing Content",
289
- )
290
- output_text = gr.Textbox(label="Analysis Results")
 
 
 
 
 
 
 
 
 
291
 
292
- analyze_btn = gr.Button("Analyze", variant="primary")
293
- analyze_btn.click(fn=analyze, inputs=input_text, outputs=output_text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
- gr.Examples(
296
- examples=[
297
- "WordLift is an AI-powered SEO tool",
298
- "Our advanced machine learning algorithms optimize your content",
299
- "Simple and effective website optimization",
300
- ],
301
  inputs=input_text,
 
302
  )
303
 
304
  return interface
 
247
  def analyze(text):
248
  results = analyzer.analyze_content(text)
249
 
250
+ output = "# Content Analysis Results\n\n"
251
 
252
+ output += "## Category Scores\n"
253
  for category, features in results["categories"].items():
254
  if features:
255
  avg_score = np.mean([f["activation_score"] for f in features])
256
+ output += f"**{category.title()}**: {avg_score:.2f}\n"
257
 
258
+ output += "\n## Feature Details\n"
259
  for feature_id, feature in results["features"].items():
260
+ output += f"\n### {feature['name']} (Feature {feature_id})\n"
261
+ output += f"**Score**: {feature['activation_score']:.2f}\n\n"
262
+ output += f"**Interpretation**: {feature['interpretation']}\n\n"
263
+ # Add feature explanation from Neuronpedia reference
264
+ output += f"[View feature details on Neuronpedia](https://neuronpedia.org/gemma-2-2b/20-gemmascope-res-16k/{feature_id})\n\n"
265
 
266
  if results["recommendations"]:
267
+ output += "\n## Recommendations\n"
268
  for rec in results["recommendations"]:
269
  output += f"- {rec}\n"
270
 
271
+ feature_id = max(
272
+ results["features"].items(), key=lambda x: x[1]["activation_score"]
273
+ )[0]
274
+
275
+ # Build dashboard URL for the highest activating feature
276
+ dashboard_url = f"https://neuronpedia.org/gemma-2-2b/20-gemmascope-res-16k/{feature_id}?embed=true&embedexplanation=true&embedplots=true&embedtest=true&height=300"
277
+
278
+ return output, dashboard_url, feature_id
279
 
280
  with gr.Blocks(
281
  theme=gr.themes.Default(
 
291
  )
292
 
293
  with gr.Row():
294
+ with gr.Column(scale=1):
295
+ input_text = gr.Textbox(
296
+ lines=5,
297
+ placeholder="Enter your marketing content here...",
298
+ label="Marketing Content",
299
+ )
300
+ analyze_btn = gr.Button("Analyze", variant="primary")
301
+ gr.Examples(
302
+ examples=[
303
+ "WordLift is an AI-powered SEO tool",
304
+ "Our advanced machine learning algorithms optimize your content",
305
+ "Simple and effective website optimization",
306
+ ],
307
+ inputs=input_text,
308
+ )
309
 
310
+ with gr.Column(scale=2):
311
+ output_text = gr.Markdown(label="Analysis Results")
312
+ with gr.Box():
313
+ gr.Markdown("## Feature Dashboard")
314
+ feature_id_text = gr.Text(
315
+ label="Currently viewing feature", show_label=False
316
+ )
317
+ dashboard_frame = gr.HTML(label="Feature Dashboard")
318
+
319
+ def update_dashboard(text):
320
+ output, dashboard_url, feature_id = analyze(text)
321
+ return (
322
+ output,
323
+ f"<iframe src='{dashboard_url}' width='100%' height='600px' frameborder='0'></iframe>",
324
+ f"Currently viewing Feature {feature_id} - Most active feature in your content",
325
+ )
326
 
327
+ analyze_btn.click(
328
+ fn=update_dashboard,
 
 
 
 
329
  inputs=input_text,
330
+ outputs=[output_text, dashboard_frame, feature_id_text],
331
  )
332
 
333
  return interface