Mjwarren3's picture
Separating functions
d01c2e9
raw
history blame
1.66 kB
import gradio as gr
def main_function(input_text, target_level, action):
if action == "Calculate Input Level":
return calc_input_reading_level(input_text), None, None, None
elif action == "Generate Text":
output_text, output_level, similarity = get_output_text_level_and_similarity(input_text, target_level)
return None, output_text, output_level, similarity
def calc_input_reading_level(input_text):
# Placeholder function implementation.
return len(input_text) % 10 # Random operation as a placeholder
def get_output_text_level_and_similarity(input_text, target_level):
# Placeholder function implementation.
output_text = input_text[::-1] # Example operation: reverse the input
output_level = int(target_level) # Assuming target_level is directly the output level
similarity = 0.5 # Example fixed similarity
return output_text, output_level, similarity
iface = gr.Interface(
fn=main_function,
inputs=[
gr.components.Textbox(label="Input Text", lines=2),
gr.components.Dropdown(choices=["1", "2", "3", "4", "5"], label="Target Reading Level"),
gr.components.Radio(choices=["Calculate Input Level", "Generate Text"], label="Action")
],
outputs=[
gr.components.Text(label="Input Reading Level"),
gr.components.Text(label="Output Text"),
gr.components.Text(label="Output Reading Level"),
gr.components.Text(label="Output Text Similarity")
],
title="Text Analysis Tool",
description="Calculate the reading level of input text or generate and analyze new text at a specified reading level."
)
iface.launch()