Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,90 +1,75 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
-
import
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
st.
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
#
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
#
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
st.
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
if st.button("Predict"):
|
77 |
-
if user_input.strip():
|
78 |
-
# Vectorize the input text
|
79 |
-
input_vector = vectorizer.transform([user_input]).toarray()
|
80 |
-
|
81 |
-
# Predict and show the result
|
82 |
-
prediction = model.predict(input_vector)
|
83 |
-
confidence = model.predict_proba(input_vector).max() * 100
|
84 |
-
|
85 |
-
if prediction[0] == 1:
|
86 |
-
st.success(f"The text is likely **Human-Written** with a confidence of {confidence:.2f}%.")
|
87 |
-
else:
|
88 |
-
st.warning(f"The text is likely **LLM-Generated** with a confidence of {confidence:.2f}%.")
|
89 |
-
else:
|
90 |
-
st.error("Please enter some text for prediction.")
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
+
import random
|
4 |
+
|
5 |
+
# Load the dataset (replace with your actual dataset path)
|
6 |
+
df = pd.read_csv('roft.csv') # Ensure your dataset path is correct
|
7 |
+
|
8 |
+
# Initialize session state variables
|
9 |
+
if 'score' not in st.session_state:
|
10 |
+
st.session_state.score = 0
|
11 |
+
if 'index' not in st.session_state:
|
12 |
+
st.session_state.index = 0
|
13 |
+
if 'game_over' not in st.session_state:
|
14 |
+
st.session_state.game_over = False
|
15 |
+
|
16 |
+
# Function to get next text from the dataset
|
17 |
+
def get_next_text():
|
18 |
+
# If game is over, return None to stop
|
19 |
+
if st.session_state.game_over:
|
20 |
+
return None
|
21 |
+
# Fetch the next text in sequence
|
22 |
+
text_data = df.iloc[st.session_state.index]
|
23 |
+
|
24 |
+
# Combine the prompt body and generation body to form the text to classify
|
25 |
+
prompt_text = text_data['prompt_body']
|
26 |
+
gen_text = text_data['gen_body']
|
27 |
+
|
28 |
+
# Combine the text and make sure it doesn't exceed 10 sentences
|
29 |
+
full_text = prompt_text + " _SEP_ " + gen_text
|
30 |
+
return full_text, text_data['model'], text_data['true_boundary_index']
|
31 |
+
|
32 |
+
# Function to update the game state
|
33 |
+
def update_game_state(user_answer, correct_answer):
|
34 |
+
# Check if answer is correct
|
35 |
+
if user_answer == correct_answer:
|
36 |
+
st.session_state.score += 5
|
37 |
+
st.session_state.index += 1
|
38 |
+
if st.session_state.index >= len(df):
|
39 |
+
st.session_state.game_over = True
|
40 |
+
st.success("Congratulations! You've completed the quiz.")
|
41 |
+
else:
|
42 |
+
st.session_state.game_over = True
|
43 |
+
st.error("Game Over! Incorrect Answer.")
|
44 |
+
|
45 |
+
# Display the score
|
46 |
+
st.sidebar.text(f"Score: {st.session_state.score}")
|
47 |
+
|
48 |
+
# Show the current text to classify
|
49 |
+
text, model_used, true_boundary_index = get_next_text()
|
50 |
+
|
51 |
+
if text:
|
52 |
+
# Display the text
|
53 |
+
st.write(f"Model used: {model_used}")
|
54 |
+
st.write(f"Text: {text}")
|
55 |
+
|
56 |
+
# User input (radio buttons for classification)
|
57 |
+
user_answer = st.radio("Classify the text as:", ["human", "machine"])
|
58 |
+
|
59 |
+
# When user submits answer
|
60 |
+
if st.button("Submit"):
|
61 |
+
# Correct answer is determined based on boundary index
|
62 |
+
correct_answer = "human" if true_boundary_index == 0 else "machine"
|
63 |
+
update_game_state(user_answer, correct_answer)
|
64 |
+
else:
|
65 |
+
# Game over message
|
66 |
+
st.write("Game Over!")
|
67 |
+
st.write(f"Your final score is: {st.session_state.score}")
|
68 |
+
|
69 |
+
# Option to restart the game
|
70 |
+
if st.session_state.game_over:
|
71 |
+
if st.button("Restart Game"):
|
72 |
+
st.session_state.score = 0
|
73 |
+
st.session_state.index = 0
|
74 |
+
st.session_state.game_over = False
|
75 |
+
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|