Add application file
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from io import StringIO
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
# Creating a sample dataframe
|
| 7 |
+
df = pd.DataFrame({
|
| 8 |
+
"Rank" : [1, 2, 3, 4, 5],
|
| 9 |
+
"Detector" : ["""Roberta Detector\n(Numo et al.)\n<a href='https://www.google.de' style="color:blue">Google</a>""", """LLM Detector
|
| 10 |
+
*(Numo et al.)*
|
| 11 |
+
<span style="color:blue">[Google](https://www.google.de)</span>
|
| 12 |
+
""", "", "", ""],
|
| 13 |
+
"All Gen. [F1]" : [20, 20, 7, 8, 7],
|
| 14 |
+
"Llama-2 7B Gen. [F1]" : [14, 3, 6, 2, 6],
|
| 15 |
+
"GPT-4 Gen. [F1]" : [23, 45, 2, 32, 2]
|
| 16 |
+
})
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def process_csv_text(temp_file):
|
| 20 |
+
if isinstance(temp_file, str):
|
| 21 |
+
df = pd.read_csv(StringIO(temp_file), parse_dates=["Start date", "End date"])
|
| 22 |
+
else:
|
| 23 |
+
df = pd.read_csv(temp_file.name, parse_dates=["Start date", "End date"])
|
| 24 |
+
print(df)
|
| 25 |
+
return df
|
| 26 |
+
|
| 27 |
+
numeric_cols = df.select_dtypes(include='number').columns
|
| 28 |
+
traget_cols = ['All Gen. [F1]', 'Llama-2 7B Gen. [F1]', 'GPT-4 Gen. [F1]']
|
| 29 |
+
|
| 30 |
+
# Applying style to highlight the maximum value in each row
|
| 31 |
+
#styler = df.style.highlight_max(color = 'lightgreen', axis = 0)
|
| 32 |
+
styler = df.style.set_properties(**{'text-align': 'center'},subset=['Detector'])\
|
| 33 |
+
.highlight_max(color='lightgreen', axis=0, subset=traget_cols)
|
| 34 |
+
title = "Test"
|
| 35 |
+
desc = "Test gradio"
|
| 36 |
+
# Displaying the styled dataframe in Gradio
|
| 37 |
+
with gr.Blocks() as demo:
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
gr.Markdown(
|
| 41 |
+
"""
|
| 42 |
+
# <center>Hello World!</center>
|
| 43 |
+
<center>Start typing below to see the output.</center>
|
| 44 |
+
""")
|
| 45 |
+
gr.DataFrame(styler, line_breaks=True, datatype="markdown")
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# Upload table
|
| 49 |
+
gr.Markdown(
|
| 50 |
+
"""
|
| 51 |
+
# <center>Hello World!</center>
|
| 52 |
+
<center>Start typing below to see the output.</center>
|
| 53 |
+
""")
|
| 54 |
+
|
| 55 |
+
upload_button = gr.UploadButton(label="Upload Predictions", file_types = ['.csv'], live=True, file_count = "single")
|
| 56 |
+
table = gr.Dataframe(headers=["Start date", "End date"], type="pandas", col_count=2)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
upload_button.upload(fn=process_csv_text, inputs=upload_button, outputs=table, api_name="upload_csv")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
demo.launch()
|