Spaces:
Sleeping
Sleeping
Download app.py from abischoff/ContentChecker: direct link, hf CLI and curl.
- Browser
- Download file 1.99 kB
-
https://huggingface.co/spaces/abischoff/ContentChecker/resolve/main/app.py
- Command line
-
hf download hf://spaces/abischoff/ContentChecker/app.py
-
curl -L -o app.py https://huggingface.co/spaces/abischoff/ContentChecker/resolve/main/app.py
1.99 kB
| import streamlit as st | |
| import numpy as np | |
| from transformers import Trainer, AutoTokenizer, XLMRobertaForSequenceClassification | |
| import torch | |
| import pickle | |
| import re | |
| def checker(content): | |
| sentences = re.split(r"(?<=[!.;?:])\s+(?![a-zà-öø-ÿα-ωа-яא-תء-ي])", content.decode('utf-8')) | |
| model_name = "abischoff/test-trainer" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = XLMRobertaForSequenceClassification.from_pretrained(model_name,num_labels=1) | |
| sum = 0.0 | |
| bias = -0.0666 | |
| for dic in sentences: | |
| inputs = tokenizer(dic.strip(), return_tensors="pt") | |
| with torch.no_grad(): | |
| logits = model(**inputs).logits.flatten()[0].numpy()+bias | |
| logits = np.clip(logits,0,1) | |
| print(logits) | |
| sum += logits | |
| return sum / len(content) | |
| def main(): | |
| # Setze den Titel und eine moderne Überschrift | |
| st.title("Checker") | |
| st.markdown(""" | |
| <style> | |
| .reportview-container { | |
| background-color: #f4f4f9; | |
| } | |
| h1 { | |
| color: #4F8BF9; | |
| } | |
| footer { | |
| visibility: hidden; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| # Erstelle das Drag&Drop Upload-Feld für alle Dateiformate | |
| uploaded_file = st.file_uploader("Drag & Drop your file here", type=None) | |
| # Prüfen, ob eine Datei hochgeladen wurde | |
| if uploaded_file is not None: | |
| # Anzeige des Dateinamens | |
| st.write(f"File uploaded: {uploaded_file.name}") | |
| # Wenn die Datei eine Text- oder CSV-Datei ist, zeige den Inhalt an | |
| if uploaded_file.name.endswith('.txt') or uploaded_file.name.endswith('.csv'): | |
| content = uploaded_file.read().decode("utf-8") | |
| st.text_area("File Content", content, height=300) | |
| # Wenn andere Dateiformate hochgeladen werden, zeige eine Nachricht an | |
| else: | |
| st.write(f"Unsupported file type: {uploaded_file.name.split('.')[-1]}") | |
| else: | |
| st.write("Please upload a file.") | |