Mamadou2727 commited on
Commit
e760927
·
1 Parent(s): f9fe93a

update the app

Browse files
Files changed (1) hide show
  1. app.py +57 -30
app.py CHANGED
@@ -278,31 +278,56 @@ class ZarmaLanguageAnalyzer:
278
  "retrieved_context": reliable_context
279
  }
280
 
281
- def format_output(self, results: dict) -> str:
282
- """Format the analysis results for Gradio output."""
283
- output = "=" * 80 + "\n"
284
- output += "ZARMA LANGUAGE ANALYZER\n"
285
- output += "=" * 80 + "\n\n"
286
-
287
- output += "SENTENCE ANALYZED:\n"
288
- output += f" \"{results['sentence']}\"\n\n"
289
-
290
- output += "GRAMMAR STATUS:\n"
291
- output += f" {'Issues detected' if results['grammar_issues'] else 'Correct'}\n"
292
- output += "-" * 80 + "\n"
293
-
294
- output += "DETAILED ANALYSIS:\n"
295
- output += results["analysis_result"] + "\n"
296
- output += "-" * 80 + "\n"
297
-
298
- output += "RELIABLE CONTEXT SOURCES:\n"
299
- if results["retrieved_context"]:
300
- for i, context in enumerate(results["retrieved_context"], 1):
301
- output += f"Source {i}:\n"
302
- output += context + "\n\n"
303
- else:
304
- output += " No reliable context sources retrieved based on the analysis.\n"
305
- output += "=" * 80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
 
307
  return output
308
 
@@ -310,11 +335,12 @@ class ZarmaLanguageAnalyzer:
310
  analyzer = ZarmaLanguageAnalyzer("grammar_rules.json", "glossary.json")
311
 
312
  # Gradio interface
313
- def analyze_zarma_sentence(sentence):
314
  if not sentence.strip():
315
- return "Please enter a valid Zarma sentence."
316
  results = analyzer.analyze_sentence(sentence)
317
- return analyzer.format_output(results)
 
318
 
319
  # Define the Gradio UI
320
  with gr.Blocks(title="Zarma Language Analyzer") as demo:
@@ -322,14 +348,15 @@ with gr.Blocks(title="Zarma Language Analyzer") as demo:
322
  gr.Markdown("Enter a Zarma sentence below to analyze its grammar and meaning.")
323
 
324
  sentence_input = gr.Textbox(label="Zarma Sentence", placeholder="e.g., Ay ga koy.")
 
325
  analyze_button = gr.Button("Analyze")
326
  output_text = gr.Textbox(label="Analysis Result", lines=20)
327
 
328
  analyze_button.click(
329
  fn=analyze_zarma_sentence,
330
- inputs=sentence_input,
331
  outputs=output_text
332
  )
333
 
334
  # Launch the app
335
- demo.launch()
 
278
  "retrieved_context": reliable_context
279
  }
280
 
281
+ def format_output(self, results: dict, lang: str = "en") -> str:
282
+ """Format the analysis results for Gradio output in the selected language."""
283
+ if lang == "fr":
284
+ output = "=" * 80 + "\n"
285
+ output += "ANALYSEUR DE LANGUE ZARMA\n"
286
+ output += "=" * 80 + "\n\n"
287
+
288
+ output += "PHRASE ANALYSÉE :\n"
289
+ output += f" \"{results['sentence']}\"\n\n"
290
+
291
+ output += "ÉTAT DE LA GRAMMAIRE :\n"
292
+ output += f" {'Problèmes détectés' if results['grammar_issues'] else 'Correct'}\n"
293
+ output += "-" * 80 + "\n"
294
+
295
+ output += "ANALYSE DÉTAILLÉE :\n"
296
+ output += results["analysis_result"] + "\n"
297
+ output += "-" * 80 + "\n"
298
+
299
+ output += "SOURCES DE CONTEXTE FIABLES :\n"
300
+ if results["retrieved_context"]:
301
+ for i, context in enumerate(results["retrieved_context"], 1):
302
+ output += f"Source {i} :\n"
303
+ output += context + "\n\n"
304
+ else:
305
+ output += " Aucune source de contexte fiable récupérée basée sur l'analyse.\n"
306
+ output += "=" * 80
307
+ else: # Default to English
308
+ output = "=" * 80 + "\n"
309
+ output += "ZARMA LANGUAGE ANALYZER\n"
310
+ output += "=" * 80 + "\n\n"
311
+
312
+ output += "SENTENCE ANALYZED:\n"
313
+ output += f" \"{results['sentence']}\"\n\n"
314
+
315
+ output += "GRAMMAR STATUS:\n"
316
+ output += f" {'Issues detected' if results['grammar_issues'] else 'Correct'}\n"
317
+ output += "-" * 80 + "\n"
318
+
319
+ output += "DETAILED ANALYSIS:\n"
320
+ output += results["analysis_result"] + "\n"
321
+ output += "-" * 80 + "\n"
322
+
323
+ output += "RELIABLE CONTEXT SOURCES:\n"
324
+ if results["retrieved_context"]:
325
+ for i, context in enumerate(results["retrieved_context"], 1):
326
+ output += f"Source {i}:\n"
327
+ output += context + "\n\n"
328
+ else:
329
+ output += " No reliable context sources retrieved based on the analysis.\n"
330
+ output += "=" * 80
331
 
332
  return output
333
 
 
335
  analyzer = ZarmaLanguageAnalyzer("grammar_rules.json", "glossary.json")
336
 
337
  # Gradio interface
338
+ def analyze_zarma_sentence(sentence, output_in_english):
339
  if not sentence.strip():
340
+ return "Please enter a valid Zarma sentence." if output_in_english else "Veuillez entrer une phrase Zarma valide."
341
  results = analyzer.analyze_sentence(sentence)
342
+ lang = "en" if output_in_english else "fr"
343
+ return analyzer.format_output(results, lang=lang)
344
 
345
  # Define the Gradio UI
346
  with gr.Blocks(title="Zarma Language Analyzer") as demo:
 
348
  gr.Markdown("Enter a Zarma sentence below to analyze its grammar and meaning.")
349
 
350
  sentence_input = gr.Textbox(label="Zarma Sentence", placeholder="e.g., Ay ga koy.")
351
+ language_checkbox = gr.Checkbox(label="Output in English (uncheck for French)", value=True)
352
  analyze_button = gr.Button("Analyze")
353
  output_text = gr.Textbox(label="Analysis Result", lines=20)
354
 
355
  analyze_button.click(
356
  fn=analyze_zarma_sentence,
357
+ inputs=[sentence_input, language_checkbox],
358
  outputs=output_text
359
  )
360
 
361
  # Launch the app
362
+ demo.launch(share=True)