Spaces:
Runtime error
Runtime error
fengxiang
commited on
Commit
·
134421a
1
Parent(s):
1e73be5
update space
Browse files- app.py +103 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import (
|
3 |
+
pipeline
|
4 |
+
)
|
5 |
+
|
6 |
+
# albert
|
7 |
+
# albert_base_chinese_cluecorpussmall=pipeline(task="fill-mask", model="uer/albert-base-chinese-cluecorpussmall")
|
8 |
+
# roberta
|
9 |
+
# xlm_roberta_base=pipeline(task="fill-mask", model="xlm-roberta-base")
|
10 |
+
# xlm_roberta_large=pipeline(task="fill-mask", model="xlm-roberta-large")
|
11 |
+
# bert
|
12 |
+
pipe=pipeline(
|
13 |
+
# model="rjx/chinese-new-text-classification-10200-albert-base-chinese-cluecorpussmall",
|
14 |
+
model="rjx/rjxai-xlm-roberta-longformer-1024-and-dataset-0522",
|
15 |
+
use_auth_token=st.secrets["read_key"]
|
16 |
+
)
|
17 |
+
|
18 |
+
if 'type' not in st.session_state:
|
19 |
+
st.session_state.type=""
|
20 |
+
|
21 |
+
if 'article' not in st.session_state:
|
22 |
+
st.session_state.article=""
|
23 |
+
|
24 |
+
if 'result' not in st.session_state:
|
25 |
+
st.session_state.result=""
|
26 |
+
|
27 |
+
# def charlength():
|
28 |
+
# if len(st.session_state.article)>=512:
|
29 |
+
# st.warning("article length is 512")
|
30 |
+
|
31 |
+
def form_article_click():
|
32 |
+
# st.warning(st.session_state.model_key)
|
33 |
+
# st.warning(st.session_state.article_key)
|
34 |
+
|
35 |
+
if st.session_state.article_key == "":
|
36 |
+
st.warning("Need to enter content")
|
37 |
+
else:
|
38 |
+
article=st.session_state.article_key
|
39 |
+
# 截取大于510字符的内容
|
40 |
+
if len(article)>=1024:
|
41 |
+
article=article[0: 1024]
|
42 |
+
# st.info(article)
|
43 |
+
print(article)
|
44 |
+
result = pipe(article)
|
45 |
+
print(result)
|
46 |
+
st.session_state.type=result[0]["label"]
|
47 |
+
# if result:
|
48 |
+
# if result[0]["label"]=="Human write":
|
49 |
+
# st.session_state.type="Human writing"
|
50 |
+
# elif result[0]["label"]=="LABEL_0":
|
51 |
+
# st.session_state.type="AI writing"
|
52 |
+
st.session_state.result=result
|
53 |
+
|
54 |
+
st.title("AI write or Human write v2")
|
55 |
+
|
56 |
+
col1, col2 = st.columns(2)
|
57 |
+
|
58 |
+
with col1:
|
59 |
+
st.header("input")
|
60 |
+
with st.form(key="article_form"):
|
61 |
+
# 模型选择
|
62 |
+
# option_input = st.selectbox(
|
63 |
+
# 'select rjx model:(Other model making)',
|
64 |
+
# ('chinese-new-text-classification-10200-albert-base-chinese-cluecorpussmall', 'other'),
|
65 |
+
# disabled=True,
|
66 |
+
# key='model_key',
|
67 |
+
# # on_change=charlength
|
68 |
+
# )
|
69 |
+
# 文本输入
|
70 |
+
article_input=st.text_area(
|
71 |
+
'content',
|
72 |
+
height=270,
|
73 |
+
key='article_key'
|
74 |
+
)
|
75 |
+
# 提交按钮
|
76 |
+
submit_button=st.form_submit_button(label='submit', on_click=form_article_click)
|
77 |
+
|
78 |
+
with col2:
|
79 |
+
st.header("output")
|
80 |
+
st.text_input('classification', st.session_state.type, disabled=True)
|
81 |
+
# st.text_area(
|
82 |
+
# 'result',
|
83 |
+
# st.session_state.result,
|
84 |
+
# height=270,
|
85 |
+
# disabled=True
|
86 |
+
# )
|
87 |
+
|
88 |
+
|
89 |
+
# st.write('selected classification model:', option)
|
90 |
+
|
91 |
+
|
92 |
+
# file_name = st.file_uploader("Upload a hot dog candidate image")
|
93 |
+
|
94 |
+
# if file_name is not None:
|
95 |
+
# col1, col2 = st.columns(2)
|
96 |
+
|
97 |
+
# image = Image.open(file_name)
|
98 |
+
# col1.image(image, use_column_width=True)
|
99 |
+
# predictions = pipeline(image)
|
100 |
+
|
101 |
+
# col2.header("Probabilities")
|
102 |
+
# for p in predictions:
|
103 |
+
# col2.subheader(f"{ p['label'] }: { round(p['score'] * 100, 1)}%")
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|