Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
from transformers import Trainer, AutoTokenizer, XLMRobertaForSequenceClassification
|
| 4 |
+
import torch
|
| 5 |
+
import pickle
|
| 6 |
+
import re
|
| 7 |
+
|
| 8 |
+
def checker(content):
|
| 9 |
+
sentences = re.split(r"(?<=[!.;?:])\s+(?![a-z脿-枚酶-每伪-蠅邪-褟讗-转亍-賷])", content.decode('utf-8'))
|
| 10 |
+
model_name = "abischoff/test-trainer"
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 12 |
+
model = XLMRobertaForSequenceClassification.from_pretrained(model_name,num_labels=1)
|
| 13 |
+
sum = 0.0
|
| 14 |
+
bias = -0.0666
|
| 15 |
+
for dic in sentences:
|
| 16 |
+
inputs = tokenizer(dic.strip(), return_tensors="pt")
|
| 17 |
+
with torch.no_grad():
|
| 18 |
+
logits = model(**inputs).logits.flatten()[0].numpy()+bias
|
| 19 |
+
logits = np.clip(logits,0,1)
|
| 20 |
+
print(logits)
|
| 21 |
+
sum += logits
|
| 22 |
+
|
| 23 |
+
return sum / len(content)
|
| 24 |
+
|
| 25 |
+
def main():
|
| 26 |
+
# Setze den Titel und eine moderne 脺berschrift
|
| 27 |
+
st.title("Checker")
|
| 28 |
+
st.markdown("""
|
| 29 |
+
<style>
|
| 30 |
+
.reportview-container {
|
| 31 |
+
background-color: #f4f4f9;
|
| 32 |
+
}
|
| 33 |
+
h1 {
|
| 34 |
+
color: #4F8BF9;
|
| 35 |
+
}
|
| 36 |
+
footer {
|
| 37 |
+
visibility: hidden;
|
| 38 |
+
}
|
| 39 |
+
</style>
|
| 40 |
+
""", unsafe_allow_html=True)
|
| 41 |
+
|
| 42 |
+
# Erstelle das Drag&Drop Upload-Feld f眉r alle Dateiformate
|
| 43 |
+
uploaded_file = st.file_uploader("Drag & Drop your file here", type=None)
|
| 44 |
+
|
| 45 |
+
# Pr眉fen, ob eine Datei hochgeladen wurde
|
| 46 |
+
if uploaded_file is not None:
|
| 47 |
+
# Anzeige des Dateinamens
|
| 48 |
+
st.write(f"File uploaded: {uploaded_file.name}")
|
| 49 |
+
|
| 50 |
+
# Wenn die Datei eine Text- oder CSV-Datei ist, zeige den Inhalt an
|
| 51 |
+
if uploaded_file.name.endswith('.txt') or uploaded_file.name.endswith('.csv'):
|
| 52 |
+
content = uploaded_file.read().decode("utf-8")
|
| 53 |
+
st.text_area("File Content", content, height=300)
|
| 54 |
+
|
| 55 |
+
# Wenn andere Dateiformate hochgeladen werden, zeige eine Nachricht an
|
| 56 |
+
else:
|
| 57 |
+
st.write(f"Unsupported file type: {uploaded_file.name.split('.')[-1]}")
|
| 58 |
+
else:
|
| 59 |
+
st.write("Please upload a file.")
|