chkla commited on
Commit
dd5343c
·
1 Parent(s): c666d78

add app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from transformers import AutoModelForSeq2SeqLM
3
+ from transformers import AutoTokenizer
4
+ import gradio as gr
5
+ import torch
6
+
7
+ # Load trained model
8
+ model = AutoModelForSeq2SeqLM.from_pretrained("chkla/parlbert-topic-german")
9
+ tokenizer = AutoTokenizer.from_pretrained("bert-base-german-cased")
10
+ pipeline_classification_topics = pipeline("text-classification", model="chkla/parlbert-topic-german", tokenizer="bert-base-german-cased", return_all_scores=False)
11
+
12
+ def predict_topic(input_text):
13
+ reframed_text = pipeline_classification_topics(input_text)
14
+ return reframed_text
15
+
16
+ # Build Gradio interface
17
+ with gr.Blocks() as demo:
18
+ # Instruction
19
+ gr.Markdown('''Topic Modelling for German Political Texts''')
20
+
21
+ # Input text to be reframed
22
+ text = gr.Textbox(label="Text")
23
+
24
+ # Trigger button for topic prediction
25
+ greet_btn = gr.Button("Predict Topic")
26
+ greet_btn.click(fn=predict_topic, inputs=[text], outputs=[gr.outputs.Textbox(label="Topic")])
27
+
28
+ # Default examples of text and strategy pairs for user to have a quick start
29
+ gr.Markdown("## Examples")
30
+ # gr.Examples(
31
+ # [["I have a lot of homework to do today.", "self_affirmation"], ["So stressed about the midterm next week.", "optimism"], ["I failed my math quiz I am such a loser.", "growth"]],
32
+ # [text], best_output, show_reframe_change, cache_examples=False, run_on_click=False
33
+ # )
34
+
35
+ # Link to paper and Github repo
36
+ gr.Markdown('''For more details: You can read our [paper]() or access our [code]().''')
37
+
38
+ demo.launch()