Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
|
| 3 |
+
# Load model directly
|
| 4 |
+
from transformers import (AutoTokenizer,
|
| 5 |
+
AutoModelForSequenceClassification,
|
| 6 |
+
TextClassificationPipeline)
|
| 7 |
+
|
| 8 |
+
tokenizer = AutoTokenizer.from_pretrained("Hello-SimpleAI/chatgpt-detector-roberta")
|
| 9 |
+
model = AutoModelForSequenceClassification.from_pretrained("Hello-SimpleAI/chatgpt-detector-roberta")
|
| 10 |
+
|
| 11 |
+
pipe = TextClassificationPipeline(model=model, tokenizer=tokenizer, return_all_scores=True)
|
| 12 |
+
|
| 13 |
+
def score_and_visualize(text):
|
| 14 |
+
prediction = pipe([text])
|
| 15 |
+
f_score = 0
|
| 16 |
+
f_label = ""
|
| 17 |
+
label_0 = prediction[0][0]['label']
|
| 18 |
+
score_0 = prediction[0][0]['score']
|
| 19 |
+
label_1 = prediction[0][1]['label']
|
| 20 |
+
score_1 = prediction[0][1]['score']
|
| 21 |
+
if score_0 > score_1:
|
| 22 |
+
f_score = (round(score_0))*100
|
| 23 |
+
f_label = label_0
|
| 24 |
+
else:
|
| 25 |
+
f_score = (round(score_1))*100
|
| 26 |
+
f_label = label_1
|
| 27 |
+
return f_score, f_label
|
| 28 |
+
|
| 29 |
+
def main():
|
| 30 |
+
st.title("Human vs ChatGPT Classification Model")
|
| 31 |
+
|
| 32 |
+
# Create an input text box
|
| 33 |
+
input_text = st.text_area("Enter your text", "")
|
| 34 |
+
|
| 35 |
+
# Create a button to trigger model inference
|
| 36 |
+
if st.button("Analyze"):
|
| 37 |
+
# Perform inference using the loaded model
|
| 38 |
+
score, label = score_and_visualize(input_text)
|
| 39 |
+
st.write("The input text is ", str(score), " ", label , " based.")
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
main()
|