Spaces:
Runtime error
Runtime error
File size: 2,514 Bytes
dd5343c 067d9fd dd5343c 2e65e28 dd5343c 067d9fd dd5343c e58ba9c dd5343c 9630bcb 68fc143 dd5343c da93c4d dd5343c f7f2276 68fc143 dd5343c e58ba9c e84372d dd5343c 067d9fd e58ba9c e84372d e58ba9c e84372d 067d9fd e58ba9c d3adc06 9630bcb dd5343c abf14b3 dd5343c 2e65e28 |
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 |
from transformers import pipeline
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
import gradio as gr
import torch
import pandas as pd
# Load trained model
model = AutoModelForSequenceClassification.from_pretrained("chkla/parlbert-topic-german")
tokenizer = AutoTokenizer.from_pretrained("bert-base-german-cased")
pipeline_classification_topics = pipeline("text-classification", model="chkla/parlbert-topic-german", tokenizer="bert-base-german-cased", return_all_scores=False)
def upload_file(files):
file_paths = [file.name for file in files]
return file_paths
def predict_topic(input_text):
prediction = pipeline_classification_topics(input_text)
# predicted_label = prediction[0]['label']
return prediction[0]['label']
# Build Gradio interface
with gr.Blocks() as demo:
# Instruction
gr.Markdown('''## Topic Modelling for German Political Texts''')
# Input text to be reframed
text = gr.Textbox(label="Text")
# predictions = gr.outputs.Textbox(label="Topic")
predictions = gr.Label()
# Trigger button for topic prediction
greet_btn = gr.Button("Predict Topic")
greet_btn.click(fn=predict_topic, inputs=[text], outputs=[predictions])
# Default examples of text and strategy pairs for user to have a quick start
gr.Markdown("## Examples")
gr.Examples(
["Sachgebiet Ausschließliche Gesetzgebungskompetenz des Bundes über die Zusammenarbeit des Bundes und der Länder zum Schutze der freiheitlichen demokratischen Grundordnung, des Bestandes und der Sicherheit des Bundes oder eines Landes.", "Sachgebiet Investive Ausgaben des Bundes Bundesfinanzminister Apel hat gemäß BMF Finanznachrichten vom . Januar erklärt , die Investitionsquote des Bundes sei in den letzten zehn Jahren nahezu konstant geblieben."],
[text],
[predictions],
fn=predict_topic,
cache_examples=True,
)
# Upload file
# file_output = gr.File()
# upload_button = gr.UploadButton("Click to Upload a File", outputs=[file_output])
# gr.Dataframe(pd.DataFrame(file_output))
# Link to paper and Github repo
gr.Markdown('''For more details: You can read our [paper](http://www.lrec-conf.org/proceedings/lrec2022/workshops/ParlaCLARINIII/pdf/2022.parlaclariniii-1.13.pdf) or access our [code](https://github.com/chkla/FrameASt).''')
gr.Markdown('''Enjoy and stay tuned 🚀''')
def main():
demo.launch()
if __name__ == "__main__":
main()
|