Unavailable1's picture
Update app.py
4a571df verified
import gradio as gr
import time
from transformers import pipeline
# Load the speed reading model from Hugging Face Spaces
speed_reading = pipeline("text-classification", model="sberbank-ai/rugpt3small_based_on_gpt2")
def perform_speed_reading(text):
# Split the text into individual sentences
sentences = text.split(".")
# Initialize variables to store results
words_read = 0
time_taken = 0
# Loop through each sentence and read it using speed reading model
for sentence in sentences:
# Measure time taken to read each sentence
start_time = time.time()
# Read the sentence using speed reading model
speed_reading(sentence)
# Calculate time taken to read the sentence
end_time = time.time()
time_taken += end_time - start_time
# Count the number of words read
words_read += len(sentence.split())
# Calculate reading speed in words per minute (WPM)
wpm = (words_read / time_taken) * 60
return words_read, time_taken, wpm
# Interface
def speed_reading_interface(text):
words_read, time_taken, wpm = perform_speed_reading(text)
return f"Words Read: {words_read}, Time Taken (seconds): {time_taken}, Reading Speed (WPM): {wpm}"
inputs = gr.inputs.Textbox(placeholder="Enter text here")
output = gr.outputs.Textbox(label="Results")
gr.Interface()
fn=speed_reading_interface,
inputs=inputs,
outputs=output,
title="Speed Reading Test",
description="Enter the text you want to speed read, and see how many words you can read per minute.",
.launch()