Download app.py from Equityone/teetch: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/Equityone/teetch/resolve/main/app.py
- Command line
-
hf download hf://spaces/Equityone/teetch/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Equityone/teetch/resolve/main/app.py
1.18 kB
| import gradio as gr | |
| from PIL import Image | |
| import random | |
| # Exemple de base de données de mots | |
| WORDS_DATABASE = { | |
| "cat": {"fr": "chat", "audio": None}, | |
| "house": {"fr": "maison", "audio": None}, | |
| } | |
| # Simule un modèle de reconnaissance d'image | |
| def recognize_object(image): | |
| return random.choice(list(WORDS_DATABASE.keys())) | |
| # Fonction principale | |
| def handle_drawing(image): | |
| recognized_object = recognize_object(image) | |
| french_translation = WORDS_DATABASE.get(recognized_object, {}).get("fr", "Inconnu") | |
| response = f"Objet reconnu : {recognized_object.capitalize()} (Français : {french_translation})" | |
| return response, None | |
| # Interface utilisateur | |
| def create_interface(): | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Apprends l'Anglais en Dessinant !") | |
| canvas = gr.Sketchpad(label="Dessine ici !", shape=(256, 256)) | |
| response_text = gr.Textbox(label="Résultat", interactive=False) | |
| submit_button = gr.Button("Reconnaître") | |
| submit_button.click(handle_drawing, inputs=[canvas], outputs=[response_text, None]) | |
| return demo | |
| # Lancement | |
| if __name__ == "__main__": | |
| demo = create_interface() | |
| demo.launch() | |