Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
| 4 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# summary function - test for single gradio function interfrace
|
| 8 |
def bulk_function(filename):
|
|
@@ -17,6 +38,9 @@ def bulk_function(filename):
|
|
| 17 |
def __getitem__(self, idx):
|
| 18 |
return {k: v[idx] for k, v in self.tokenized_texts.items()}
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
# load tokenizer and model, create trainer
|
| 21 |
model_name = "j-hartmann/emotion-english-distilroberta-base"
|
| 22 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
@@ -106,11 +130,12 @@ def bulk_function(filename):
|
|
| 106 |
# return dataframe for space output
|
| 107 |
return YOUR_FILENAME
|
| 108 |
|
| 109 |
-
gr.Interface(bulk_function,
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
title="Emotion Classification from CSV",
|
| 114 |
-
description="Upload csv file with 2 columns (in order): (a) ID column, (b) text column.
|
| 115 |
allow_flagging=False,
|
| 116 |
).launch(debug=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import pandas as pd
|
| 3 |
import numpy as np
|
| 4 |
+
import spacy
|
| 5 |
+
from spacy import displacy
|
| 6 |
+
|
| 7 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, Trainer
|
| 8 |
|
| 9 |
+
def linkify():
|
| 10 |
+
import pandas as pd
|
| 11 |
+
import streamlit as st
|
| 12 |
+
link1 = "https://stackoverflow.com/questions/71641666/hyperlink-in-streamlit-dataframe"
|
| 13 |
+
link2 = "https://stackoverflow.com/questions/71731937/how-to-plot-comparison-in-streamlit-dynamically-with-multiselect"
|
| 14 |
+
df = pd.DataFrame(
|
| 15 |
+
{
|
| 16 |
+
"url": [
|
| 17 |
+
f'<a target="_blank" href="{link1}">Hyperlink in Streamlit dataframe</a>',
|
| 18 |
+
f'<a target="_blank" href="{link2}">How to plot comparison in Streamlit dynamically with multiselect?</a>'
|
| 19 |
+
],
|
| 20 |
+
"label": ["question", "question"]
|
| 21 |
+
}
|
| 22 |
+
)
|
| 23 |
+
doc=df.to_html(escape=False, index=False)
|
| 24 |
+
html = displacy.render(doc, style="dep", page=True)
|
| 25 |
+
return html
|
| 26 |
+
|
| 27 |
|
| 28 |
# summary function - test for single gradio function interfrace
|
| 29 |
def bulk_function(filename):
|
|
|
|
| 38 |
def __getitem__(self, idx):
|
| 39 |
return {k: v[idx] for k, v in self.tokenized_texts.items()}
|
| 40 |
|
| 41 |
+
html = linkify()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
# load tokenizer and model, create trainer
|
| 45 |
model_name = "j-hartmann/emotion-english-distilroberta-base"
|
| 46 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
|
|
| 130 |
# return dataframe for space output
|
| 131 |
return YOUR_FILENAME
|
| 132 |
|
| 133 |
+
gr.Interface(bulk_function,
|
| 134 |
+
inputs=[gr.inputs.File(file_count="single", type="file", label="Upload file", optional=False),],
|
| 135 |
+
outputs=[gr.outputs.File(label="Output file")],
|
| 136 |
+
# examples=[["YOUR_FILENAME.csv"]], # computes, doesn't export df so far
|
| 137 |
+
theme="huggingface",
|
| 138 |
title="Emotion Classification from CSV",
|
| 139 |
+
description="Upload csv file with 2 columns (in order): (a) ID column, (b) text column. Model: https://huggingface.co/j-hartmann/emotion-english-distilroberta-base.",
|
| 140 |
allow_flagging=False,
|
| 141 |
).launch(debug=True)
|