|
import gradio as gr |
|
|
|
|
|
def minify_function(input_text, uploaded_file): |
|
if uploaded_file is not None: |
|
content = uploaded_file.read().decode("utf-8") |
|
else: |
|
content = input_text |
|
return "Hello " + content |
|
|
|
minify = gr.Interface( |
|
minify_function, |
|
[gr.Textbox(label="Input Text"), gr.File(label="Upload File")], |
|
"text" |
|
) |
|
|
|
|
|
def check_input(input_text, uploaded_file): |
|
if uploaded_file is not None: |
|
input_text = uploaded_file.read().decode("utf-8") |
|
|
|
if not input_text.strip(): |
|
return "No words in the input." |
|
words = input_text.split() |
|
response = [f"'{word}' is a valid word." if word.isalpha() and ' ' not in word else f"'{word}' is not a valid word." for word in words] |
|
return " ".join(response) |
|
|
|
should_we_translate = gr.Interface( |
|
check_input, |
|
[gr.Textbox(label="Input Text"), gr.File(label="Upload File")], |
|
"text" |
|
) |
|
|
|
|
|
demo = gr.TabbedInterface([minify, should_we_translate], ["Minify", "Should we translate?"]) |
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|