Qifan Zhang commited on
Commit ·
a917110
1
Parent(s): 8ff8b6d
chore: upgrade space to gradio 6
Browse files- README.md +3 -2
- app.py +20 -5
- requirements.txt +8 -8
README.md
CHANGED
|
@@ -4,7 +4,8 @@ emoji: 💡
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
@@ -12,4 +13,4 @@ license: mit
|
|
| 12 |
|
| 13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 14 |
|
| 15 |
-
["Automatic Assessment of Divergent Thinking in Chinese Language with TransDis: A Transformer-Based Language Model Approach"](https://arxiv.org/abs/2306.14790)
|
|
|
|
| 4 |
colorFrom: yellow
|
| 5 |
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 6.14.0
|
| 8 |
+
python_version: "3.11"
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
| 11 |
license: mit
|
|
|
|
| 13 |
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
| 15 |
|
| 16 |
+
["Automatic Assessment of Divergent Thinking in Chinese Language with TransDis: A Transformer-Based Language Model Approach"](https://arxiv.org/abs/2306.14790)
|
app.py
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
| 1 |
import traceback
|
| 2 |
from io import StringIO
|
| 3 |
from typing import Optional
|
|
@@ -10,7 +12,18 @@ from utils import pipeline
|
|
| 10 |
from utils.models import list_models
|
| 11 |
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def read_data(filepath: str) -> Optional[pd.DataFrame]:
|
|
|
|
| 14 |
if filepath.endswith('.xlsx'):
|
| 15 |
df = pd.read_excel(filepath)
|
| 16 |
elif filepath.endswith('.csv'):
|
|
@@ -31,7 +44,7 @@ def process(
|
|
| 31 |
logger.info(f'Processing {task_name} with {model_name} and {pooling}')
|
| 32 |
# load file
|
| 33 |
if file:
|
| 34 |
-
df = read_data(file
|
| 35 |
elif text:
|
| 36 |
string_io = StringIO(text)
|
| 37 |
df = pd.read_csv(string_io)
|
|
@@ -52,11 +65,12 @@ def process(
|
|
| 52 |
raise Exception('Task not supported')
|
| 53 |
|
| 54 |
# save
|
| 55 |
-
path = '
|
|
|
|
| 56 |
df.to_csv(path, index=False, encoding='utf-8-sig')
|
| 57 |
return None, df.iloc[:10], path
|
| 58 |
|
| 59 |
-
except:
|
| 60 |
error = traceback.format_exc()
|
| 61 |
logger.warning({
|
| 62 |
'error': error,
|
|
@@ -66,7 +80,7 @@ def process(
|
|
| 66 |
'text': text,
|
| 67 |
'file': file,
|
| 68 |
})
|
| 69 |
-
return
|
| 70 |
|
| 71 |
|
| 72 |
# input
|
|
@@ -104,4 +118,5 @@ app = gr.Interface(
|
|
| 104 |
title='TransDis-CreativityAutoAssessment',
|
| 105 |
concurrency_limit=1,
|
| 106 |
)
|
| 107 |
-
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
import traceback
|
| 4 |
from io import StringIO
|
| 5 |
from typing import Optional
|
|
|
|
| 12 |
from utils.models import list_models
|
| 13 |
|
| 14 |
|
| 15 |
+
def resolve_file_path(file) -> str:
|
| 16 |
+
if isinstance(file, dict) and file.get('path'):
|
| 17 |
+
return os.fspath(file['path'])
|
| 18 |
+
if isinstance(file, (str, os.PathLike)):
|
| 19 |
+
return os.fspath(file)
|
| 20 |
+
if hasattr(file, 'name'):
|
| 21 |
+
return os.fspath(file.name)
|
| 22 |
+
raise TypeError(f'Unsupported file input: {type(file)!r}')
|
| 23 |
+
|
| 24 |
+
|
| 25 |
def read_data(filepath: str) -> Optional[pd.DataFrame]:
|
| 26 |
+
filepath = os.fspath(filepath)
|
| 27 |
if filepath.endswith('.xlsx'):
|
| 28 |
df = pd.read_excel(filepath)
|
| 29 |
elif filepath.endswith('.csv'):
|
|
|
|
| 44 |
logger.info(f'Processing {task_name} with {model_name} and {pooling}')
|
| 45 |
# load file
|
| 46 |
if file:
|
| 47 |
+
df = read_data(resolve_file_path(file))
|
| 48 |
elif text:
|
| 49 |
string_io = StringIO(text)
|
| 50 |
df = pd.read_csv(string_io)
|
|
|
|
| 65 |
raise Exception('Task not supported')
|
| 66 |
|
| 67 |
# save
|
| 68 |
+
fd, path = tempfile.mkstemp(prefix='transdis_', suffix='.csv')
|
| 69 |
+
os.close(fd)
|
| 70 |
df.to_csv(path, index=False, encoding='utf-8-sig')
|
| 71 |
return None, df.iloc[:10], path
|
| 72 |
|
| 73 |
+
except Exception:
|
| 74 |
error = traceback.format_exc()
|
| 75 |
logger.warning({
|
| 76 |
'error': error,
|
|
|
|
| 80 |
'text': text,
|
| 81 |
'file': file,
|
| 82 |
})
|
| 83 |
+
return f'Something wrong\n\n{error}', None, None
|
| 84 |
|
| 85 |
|
| 86 |
# input
|
|
|
|
| 118 |
title='TransDis-CreativityAutoAssessment',
|
| 119 |
concurrency_limit=1,
|
| 120 |
)
|
| 121 |
+
if __name__ == '__main__':
|
| 122 |
+
app.launch(max_threads=1)
|
requirements.txt
CHANGED
|
@@ -1,12 +1,12 @@
|
|
| 1 |
-
numpy
|
| 2 |
-
pandas
|
| 3 |
|
| 4 |
-
transformers
|
| 5 |
-
sentence-transformers
|
| 6 |
|
| 7 |
-
torch
|
| 8 |
|
| 9 |
-
openpyxl
|
| 10 |
-
tabulate
|
| 11 |
-
loguru
|
| 12 |
# gradio
|
|
|
|
| 1 |
+
numpy<3
|
| 2 |
+
pandas>=2.2,<4
|
| 3 |
|
| 4 |
+
transformers>=4.45,<6
|
| 5 |
+
sentence-transformers>=3,<6
|
| 6 |
|
| 7 |
+
torch>=2.4,<3
|
| 8 |
|
| 9 |
+
openpyxl>=3.1,<4
|
| 10 |
+
tabulate>=0.9,<1
|
| 11 |
+
loguru>=0.7,<1
|
| 12 |
# gradio
|