File size: 791 Bytes
224ca5a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
#import transformers
#from transformers import pipeline


def sentence_analysis(sent):
  #length of token/length of type = TTR
  #length = len(sent.split())
  number_of_tokens = len(sent.lower().split())
  number_of_types = len(set(sent.lower().split()))
  TTR = number_of_types/number_of_tokens
  return (f'''Your sentence has {number_of_tokens} tokens in it. 
Your sentence has {number_of_types} types in it. 
Type-token ratio of the sentence is {TTR}. 
Please type another sentence.''')

iface = gr.Interface(fn=sentence_analysis, inputs="text", outputs="text")
iface.launch()

def word_analysis(word):
  letter_count = len(word)
  return (f'Your word has {letter_count} letters.')

iface = gr.Interface(fn=word_analysis, inputs="text", outputs="text")
iface.launch()