File size: 2,793 Bytes
18db0c3
c6546bc
18db0c3
c6546bc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import gradio as gr
import pandas as pd

# Lecture du lexique
def read_lexicon(lexicon_file):
    df = pd.read_csv(lexicon_file, sep='\t')
    df['keyword_no_cat'] = df['lemma'].str.split(' #').str[0].str.strip().str.replace(' ', '_')
    return df

lexicon = read_lexicon("lexicon.csv")

# Récupération de l'ID du pictogramme depuis le lexique
def get_id_picto_from_predicted_lemma(df_lexicon, lemma):
    lemma = lemma.strip().lower()
    if lemma.endswith("!"):
        lemma = lemma[:-1]
    id_picto = df_lexicon.loc[df_lexicon['keyword_no_cat'] == lemma, 'id_picto'].tolist()
    return (id_picto[0], lemma) if id_picto else (0, lemma)

# Génération de contenu HTML pour afficher les pictogrammes
def generate_html(ids):
    html_content = '''
    <style>
        figure {
            display: inline-block;
            text-align: center;
            font-family: Arial, sans-serif;
            margin: 10px;
        }
        figcaption {
            color: black;
            background-color: white;
            border-radius: 5px;
            margin-top: 5px;
            padding: 2px;
        }
        img {
            background-color: white;
            margin: 0;
            padding: 0;
            border-radius: 6px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
    </style>
    '''
    for picto_id, lemma in ids:
        if picto_id != 0:  # pictogramme trouvé
            img_url = f"https://static.arasaac.org/pictograms/{picto_id}/{picto_id}_500.png"
            html_content += f'''
            <figure>
                <img src="{img_url}" alt="{lemma}" width="100" height="100"/>
                <figcaption>{lemma}</figcaption>
            </figure>
            '''
        else:  # pictogramme non trouvé
            html_content += f'''
            <figure>
                <figcaption>Token "{lemma}" non trouvé dans le lexique</figcaption>
            </figure>
            '''
    return html_content

# Fonction principale de traitement
def process_text(input_text):
    tokens = input_text.strip().split()  # Découper l'entrée utilisateur en tokens
    pictogram_ids = [get_id_picto_from_predicted_lemma(lexicon, token) for token in tokens]
    return generate_html(pictogram_ids)

# Configuration de l'interface Gradio
with gr.Blocks() as demo:
    gr.Markdown("## Visualize Pictograms Application")
    gr.Markdown("Saisissez une phrase pour voir les pictogrammes correspondants.")

    with gr.Row():
        input_text = gr.Textbox(label="Entrez votre texte", placeholder="Exemple : bonjour comment ça va")
        output_html = gr.HTML(label="Résultats")

    submit_btn = gr.Button("Afficher les pictogrammes")
    submit_btn.click(process_text, inputs=input_text, outputs=output_html)

# Lancer l'application
demo.launch()