| import gradio as gr |
| from PIL import Image |
| import random |
|
|
| |
| WORDS_DATABASE = { |
| "cat": {"fr": "chat", "audio": "audio/cat.mp3"}, |
| "house": {"fr": "maison", "audio": "audio/house.mp3"}, |
| "tree": {"fr": "arbre", "audio": "audio/tree.mp3"}, |
| "dog": {"fr": "chien", "audio": "audio/dog.mp3"}, |
| } |
|
|
| |
| def recognize_object(image): |
| |
| recognized_object = random.choice(list(WORDS_DATABASE.keys())) |
| return recognized_object |
|
|
| |
| def handle_drawing(image): |
| |
| recognized_object = recognize_object(image) |
| |
| word_info = WORDS_DATABASE.get(recognized_object, {}) |
| english_word = recognized_object.capitalize() |
| french_translation = word_info.get("fr", "Inconnu") |
| audio_path = word_info.get("audio", None) |
| |
| response = f"Objet reconnu : **{english_word}** (Français : **{french_translation}**)" |
| return response, audio_path |
|
|
| |
| def create_interface(): |
| with gr.Blocks() as demo: |
| gr.Markdown("# 🖌️ Atelier de Dessin Virtuel - Apprends l'Anglais en Dessinant !") |
| gr.Markdown( |
| """ |
| 1. Dessine un objet simple (par ex., un chat, une maison, un arbre, un chien). |
| 2. L'IA essaiera de reconnaître ton dessin et te montrera le mot en anglais et français. |
| 3. Écoute la prononciation pour améliorer ton anglais ! |
| """ |
| ) |
|
|
| |
| with gr.Row(): |
| canvas = gr.Sketchpad(label="Dessine ici !", shape=(256, 256)) |
| response_text |
|
|