Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,10 +10,10 @@ tokenizer = GPT2Tokenizer.from_pretrained("gpt2-medium")
|
|
| 10 |
model = GPT2LMHeadModel.from_pretrained("gpt2-medium")
|
| 11 |
|
| 12 |
def generate_text(prompt):
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
# Read real titles from file
|
| 19 |
with open('dhar_mann_titles.txt', 'r') as file:
|
|
@@ -21,7 +21,7 @@ with open('dhar_mann_titles.txt', 'r') as file:
|
|
| 21 |
|
| 22 |
# Function to generate an AI title (dummy implementation)
|
| 23 |
def generate_ai_title():
|
| 24 |
-
inputs = tokenizer(["<|startoftext|>"]*1, return_tensors="pt")
|
| 25 |
outputs = model.generate(**inputs, max_new_tokens=50, use_cache=True, temperature=0.85, do_sample=True)
|
| 26 |
return (tokenizer.batch_decode(outputs)[0])[15:-13]
|
| 27 |
|
|
@@ -48,7 +48,7 @@ def update_options():
|
|
| 48 |
def create_interface():
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
score = gr.State(0)
|
| 51 |
-
real_index_state = gr.State(0)
|
| 52 |
|
| 53 |
score_display = gr.Markdown("## Real or AI - Dhar Mann\n**Current Score: 0**")
|
| 54 |
|
|
@@ -87,10 +87,9 @@ def create_interface():
|
|
| 87 |
continue_button.click(on_continue, inputs=score, outputs=[option1_box, option2_box, real_index_state, score_display, choice, result_text, continue_button, restart_button])
|
| 88 |
restart_button.click(on_restart, outputs=[option1_box, option2_box, real_index_state, score_display, choice, result_text, continue_button, restart_button])
|
| 89 |
|
| 90 |
-
# Set initial content for option boxes
|
| 91 |
option1_box.value = option1
|
| 92 |
option2_box.value = option2
|
| 93 |
-
real_index_state.set(real_index) # Set the initial real_index_state
|
| 94 |
|
| 95 |
return demo
|
| 96 |
|
|
|
|
| 10 |
model = GPT2LMHeadModel.from_pretrained("gpt2-medium")
|
| 11 |
|
| 12 |
def generate_text(prompt):
|
| 13 |
+
input_ids = tokenizer.encode(prompt, return_tensors="pt")
|
| 14 |
+
output = model.generate(input_ids, max_length=48, temperature=0.85, do_sample=True)
|
| 15 |
+
text = tokenizer.decode(output[0], skip_special_tokens=True)
|
| 16 |
+
return text
|
| 17 |
|
| 18 |
# Read real titles from file
|
| 19 |
with open('dhar_mann_titles.txt', 'r') as file:
|
|
|
|
| 21 |
|
| 22 |
# Function to generate an AI title (dummy implementation)
|
| 23 |
def generate_ai_title():
|
| 24 |
+
inputs = tokenizer(["<|startoftext|>"]*1, return_tensors = "pt")
|
| 25 |
outputs = model.generate(**inputs, max_new_tokens=50, use_cache=True, temperature=0.85, do_sample=True)
|
| 26 |
return (tokenizer.batch_decode(outputs)[0])[15:-13]
|
| 27 |
|
|
|
|
| 48 |
def create_interface():
|
| 49 |
with gr.Blocks() as demo:
|
| 50 |
score = gr.State(0)
|
| 51 |
+
real_index_state = gr.State(0)
|
| 52 |
|
| 53 |
score_display = gr.Markdown("## Real or AI - Dhar Mann\n**Current Score: 0**")
|
| 54 |
|
|
|
|
| 87 |
continue_button.click(on_continue, inputs=score, outputs=[option1_box, option2_box, real_index_state, score_display, choice, result_text, continue_button, restart_button])
|
| 88 |
restart_button.click(on_restart, outputs=[option1_box, option2_box, real_index_state, score_display, choice, result_text, continue_button, restart_button])
|
| 89 |
|
| 90 |
+
# Set initial content for option boxes
|
| 91 |
option1_box.value = option1
|
| 92 |
option2_box.value = option2
|
|
|
|
| 93 |
|
| 94 |
return demo
|
| 95 |
|