Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,8 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# Funktion zur Verarbeitung der hochgeladenen Datei
|
| 4 |
def process_file(file):
|
|
@@ -8,6 +12,31 @@ def process_file(file):
|
|
| 8 |
return f"Dateiinhalt:\n{content}"
|
| 9 |
return "Keine Datei hochgeladen."
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Gradio Interface
|
| 12 |
with gr.Blocks(css=".gr-box {border-radius: 8px;}") as demo:
|
| 13 |
# App-Titel
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from transformers import Trainer, AutoTokenizer, XLMRobertaForSequenceClassification
|
| 4 |
+
import torch
|
| 5 |
+
import re
|
| 6 |
|
| 7 |
# Funktion zur Verarbeitung der hochgeladenen Datei
|
| 8 |
def process_file(file):
|
|
|
|
| 12 |
return f"Dateiinhalt:\n{content}"
|
| 13 |
return "Keine Datei hochgeladen."
|
| 14 |
|
| 15 |
+
def checker(content):
|
| 16 |
+
sentences = re.split(r"(?<=[!.;?:])\s+(?![a-z脿-枚酶-每伪-蠅邪-褟讗-转亍-賷])", content.decode('utf-8'))
|
| 17 |
+
model_name = "abischoff/test-trainer"
|
| 18 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 19 |
+
model = XLMRobertaForSequenceClassification.from_pretrained(model_name,num_labels=1)
|
| 20 |
+
sum = 0.0
|
| 21 |
+
bias = -0.0666
|
| 22 |
+
for dic in sentences:
|
| 23 |
+
inputs = tokenizer(dic.strip(), return_tensors="pt")
|
| 24 |
+
with torch.no_grad():
|
| 25 |
+
logits = model(**inputs).logits.flatten()[0].numpy()+bias
|
| 26 |
+
logits = np.clip((logits,0,1)
|
| 27 |
+
print(logits)
|
| 28 |
+
sum += logits
|
| 29 |
+
|
| 30 |
+
return sum / len(content)
|
| 31 |
+
|
| 32 |
+
# Funktion zur Verarbeitung der hochgeladenen Datei
|
| 33 |
+
def process_file(file):
|
| 34 |
+
if file:
|
| 35 |
+
with open(file.name, 'r', encoding='utf-8') as f:
|
| 36 |
+
content = f.read()
|
| 37 |
+
return content
|
| 38 |
+
return None
|
| 39 |
+
|
| 40 |
# Gradio Interface
|
| 41 |
with gr.Blocks(css=".gr-box {border-radius: 8px;}") as demo:
|
| 42 |
# App-Titel
|