abischoff commited on
Commit
8b5d8bc
·
verified ·
1 Parent(s): 37a26c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -32
app.py CHANGED
@@ -1,4 +1,4 @@
1
- import gradio as gr
2
  import numpy as np
3
  from transformers import Trainer, AutoTokenizer, XLMRobertaForSequenceClassification
4
  import torch
@@ -22,36 +22,37 @@ def checker(content):
22
 
23
  return sum / len(content)
24
 
25
- # Funktion zur Verarbeitung der hochgeladenen Datei
26
- def process_file(file):
27
- if file:
28
- #with open(file.name, 'r', encoding='utf-8') as f:
29
- # content = f.read()
30
- with open(file.name, 'rb') as f:
31
- content = pickle.load(f)
32
- return content
33
- return "Datei konnte nicht gelesen werden"
 
 
 
 
 
 
34
 
35
- # Gradio Interface
36
- with gr.Blocks(css=".gr-box {border-radius: 8px;}") as demo:
37
- # App-Titel
38
- gr.Markdown(
39
- """
40
- ## 📝 Checker
41
- Ziehe deine Datei hierhin und lasse den Quality Score errechnen!
42
- """
43
- )
44
-
45
- # Drag & Drop Datei-Upload
46
- with gr.Row():
47
- with gr.Column():
48
- file_input = gr.File(label="Datei hochladen",file_types=[".txt"])
49
-
50
- with gr.Column():
51
- output_text = gr.Textbox(label="Dateiinhalt", lines=10)
52
-
53
- # Callback zum Verarbeiten der Datei
54
- file_input.change(process_file, inputs=file_input, outputs=output_text)
55
 
56
- # App starten
57
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
  import numpy as np
3
  from transformers import Trainer, AutoTokenizer, XLMRobertaForSequenceClassification
4
  import torch
 
22
 
23
  return sum / len(content)
24
 
25
+ # Setze den Titel und eine moderne Überschrift
26
+ st.title("Checker")
27
+ st.markdown("""
28
+ <style>
29
+ .reportview-container {
30
+ background-color: #f4f4f9;
31
+ }
32
+ h1 {
33
+ color: #4F8BF9;
34
+ }
35
+ footer {
36
+ visibility: hidden;
37
+ }
38
+ </style>
39
+ """, unsafe_allow_html=True)
40
 
41
+ # Erstelle das Drag&Drop Upload-Feld für alle Dateiformate
42
+ uploaded_file = st.file_uploader("Drag & Drop your file here", type=None)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+ # Prüfen, ob eine Datei hochgeladen wurde
45
+ if uploaded_file is not None:
46
+ # Anzeige des Dateinamens
47
+ st.write(f"File uploaded: {uploaded_file.name}")
48
+
49
+ # Wenn die Datei eine Text- oder CSV-Datei ist, zeige den Inhalt an
50
+ if uploaded_file.name.endswith('.txt') or uploaded_file.name.endswith('.csv'):
51
+ content = uploaded_file.read().decode("utf-8")
52
+ st.text_area("File Content", content, height=300)
53
+
54
+ # Wenn andere Dateiformate hochgeladen werden, zeige eine Nachricht an
55
+ else:
56
+ st.write(f"Unsupported file type: {uploaded_file.name.split('.')[-1]}")
57
+ else:
58
+ st.write("Please upload a file.")