Spaces:
Sleeping
Sleeping
File size: 1,430 Bytes
6d51728 ecc6e6c 84bfb61 ecc6e6c 6d51728 ecc6e6c |
1 2 3 4 5 6 7 8 9 10 11 12 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 |
import gradio as gr
import numpy as np
from textblob import TextBlob
def analyze_text(text):
if not text:
return "Please enter some text to analyze.", 0, 0, 0
blob = TextBlob(text)
sentiment = blob.sentiment.polarity
word_count = len(text.split())
char_count = len(text)
avg_word_length = char_count / word_count
return [
round(sentiment, 2),
word_count,
char_count,
round(avg_word_length, 2),
]
with gr.Blocks() as demo:
gr.Markdown("# Text Analysis App")
gr.Markdown("Enter some text to analyze its sentiment and get basic statistics.")
with gr.Row():
text_input = gr.Textbox(
label="Input Text",
placeholder="Type your text here...",
lines=5,
)
with gr.Row():
analyze_button = gr.Button("Analyze")
with gr.Row():
sentiment_output = gr.Number(label="Sentiment Score (-1 to 1)")
word_count_output = gr.Number(label="Word Count")
char_count_output = gr.Number(label="Character Count")
avg_length_output = gr.Number(label="Average Word Length")
analyze_button.click(
fn=analyze_text,
inputs=text_input,
outputs=[
sentiment_output,
word_count_output,
char_count_output,
avg_length_output,
]
)
if __name__ == "__main__":
demo.launch() |