File size: 1,191 Bytes
171689f 9a28ed0 2d1bed7 3158622 68474f5 2d1bed7 68474f5 2d1bed7 68474f5 171689f 2d1bed7 171689f 2d1bed7 9a28ed0 7742e91 4147187 c78d2b1 | 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 | import gradio as gr
# Function for the Minify interface
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"
)
# Function for the Should we translate? interface
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"
)
# Creating a Tabbed Interface with updated functionalities
demo = gr.TabbedInterface([minify, should_we_translate], ["Minify", "Should we translate?"])
if __name__ == "__main__":
demo.launch()
|