File size: 3,479 Bytes
9358f09
b1c2932
 
 
4bba8df
b1c2932
 
 
7a079bf
 
4bba8df
 
 
3414f15
92c1d67
4bba8df
 
 
27dcb52
4bba8df
 
 
 
 
 
 
 
29834f7
4bba8df
b1c2932
29834f7
4bba8df
 
 
 
 
 
 
 
 
 
 
 
 
b1c2932
 
 
 
def12b7
 
b1c2932
 
 
4bba8df
 
 
 
b1c2932
 
4bba8df
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
import os
import gradio as gr

from interfaces.cap import demo as cap_demo
from interfaces.cap_minor import demo as cap_minor_demo
from interfaces.manifesto import demo as manifesto_demo
from interfaces.sentiment import demo as sentiment_demo
from interfaces.emotion import demo as emotion_demo
from interfaces.ner import demo as ner_demo
from interfaces.ner import download_models as download_spacy_models
from interfaces.illframes import demo as illframes_demo
from interfaces.ontolisst import demo as ontolisst_demo
from interfaces.emotion9 import demo as e9_demo
from interfaces.cap_media_demo import demo as cap_media_demo
from interfaces.cap_minor_media import demo as cap_minor_media_demo
from utils import download_hf_models, df_h, set_hf_cache_dir



css = """
/* Make only the active tab bold */
.svelte-1uw5tnk[aria-selected="true"] {
    font-weight: bold;
    background: linear-gradient(to bottom right, var(--primary-100), var(--primary-300));
    color: var(--primary-600)
}
"""

with gr.Blocks(css=css) as demo:
    gr.Markdown(
        f"""
        <style>
        @import 'https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400';
        </style>
        <div style="display: block; text-align: left; padding:0; margin:0;font-family: "Source Sans Pro", Helvetica, sans-serif;">
            <h1 style="text-align: center;font-size: 17pt;">Babel Machine Demo</h1>
            <p style="font-size: 14pt;">This is a demo for text classification using language models finetuned on data labeled by <a href="https://www.comparativeagendas.net/">CAP</a>, <a href="https://manifesto-project.wzb.eu/">Manifesto Project</a>, sentiment, emotion coding and Named Entity Recognition systems.
            For the coding of complete datasets, please visit the official <a href="https://babel.poltextlab.com/">Babel Machine</a> site.<br>
            Please note that the sentiment (3) and emotions (6) models have been trained using parliamentary speech data, so the results for generic sentences may not be reliable. The emotions (9) models have been trained using <a href="https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/C9SAIX">this dataset</a>. It contains labeled parliamentary speeches and social media data. Under-represented categories were enriched with synthetic data.<br>
            <br>
            The models listed for Manifesto, Sentiment (3) and Emotions (6) tasks are a beta version and thus not publicly available, 
            the Hugging Face link will not work for them for the time being. We expect a public version after tests and improvements in the Fall. 
            Please feel free to check back for model updates, or reach out to us at that point if you wish to ask about a specific model.
            </p>
        </div>
        """)

    gr.TabbedInterface(
        interface_list=[cap_demo, cap_media_demo, cap_minor_demo, cap_minor_media_demo, manifesto_demo, sentiment_demo, emotion_demo, e9_demo,illframes_demo, ner_demo,  ontolisst_demo],
        tab_names=["CAP Major", "CAP Major + Media", "CAP Minor", "CAP Minor + Media", "Manifesto", "Sentiment (3)", "Emotions (6)","Emotions (9)", "ILLFRAMES", "Named Entity Recognition",  "ONTOLISST"]
    )

if __name__ == "__main__":
    set_hf_cache_dir("/data")
    download_spacy_models() 
    download_hf_models() # does this affect the build?
    df_h() # debug -> check disk space before launching demo
    demo.launch()

# TODO: add all languages & domains