Spaces:
Runtime error
Runtime error
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}" | |
gr.Interface() | |
fn=speed_reading_interface, | |
gr.Textbox(lines=10, placeholder="Enter text here"), | |
outputs="text" | |
launch() | |