Spaces:
Sleeping
Sleeping
Creating two sections with blocks
Browse files
app.py
CHANGED
@@ -1,38 +1,42 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def main_function(input_text, target_level, action):
|
4 |
-
if action == "Calculate Input Level":
|
5 |
-
return calc_input_reading_level(input_text), None, None, None
|
6 |
-
elif action == "Generate Text":
|
7 |
-
output_text, output_level, similarity = get_output_text_level_and_similarity(input_text, target_level)
|
8 |
-
return None, output_text, output_level, similarity
|
9 |
-
|
10 |
def calc_input_reading_level(input_text):
|
11 |
-
# Placeholder
|
12 |
-
return len(input_text) % 10 # Random operation as a placeholder
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
return output_text, output_level, similarity
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
gr.components.Radio(choices=["Calculate Input Level", "Generate Text"], label="Action")
|
27 |
-
],
|
28 |
-
outputs=[
|
29 |
-
gr.components.Text(label="Input Reading Level"),
|
30 |
-
gr.components.Text(label="Output Text"),
|
31 |
-
gr.components.Text(label="Output Reading Level"),
|
32 |
-
gr.components.Text(label="Output Text Similarity")
|
33 |
-
],
|
34 |
-
title="Text Analysis Tool",
|
35 |
-
description="Calculate the reading level of input text or generate and analyze new text at a specified reading level."
|
36 |
-
)
|
37 |
|
38 |
-
|
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
def calc_input_reading_level(input_text):
|
4 |
+
# Placeholder for actual implementation of the reading level calculation.
|
5 |
+
return len(input_text) % 10 # Random operation as a placeholder for demonstration.
|
6 |
+
|
7 |
+
def generate_and_analyze_text(input_text, target_level):
|
8 |
+
# Placeholder for generating text and analyzing it against the target level.
|
9 |
+
output_text = input_text[::-1] # Reversing text as a simple example operation.
|
10 |
+
output_reading_level = int(target_level) # Placeholder for demonstration.
|
11 |
+
similarity = 0.75 # Fixed similarity value for demonstration.
|
12 |
+
input_level = calc_input_reading_level(input_text) # Reuse the reading level calc for input level.
|
13 |
+
return input_level, output_text, output_reading_level, similarity
|
14 |
+
|
15 |
+
with gr.Blocks() as app:
|
16 |
+
with gr.Row():
|
17 |
+
with gr.Column():
|
18 |
+
input_text1 = gr.Textbox(label="Input Text for Reading Level")
|
19 |
+
button1 = gr.Button("Calculate Reading Level")
|
20 |
+
with gr.Column():
|
21 |
+
input_text2 = gr.Textbox(label="Input Text for Generation")
|
22 |
+
target_level = gr.Dropdown(choices=["1", "2", "3", "4", "5"], label="Target Reading Level")
|
23 |
+
button2 = gr.Button("Generate and Analyze Text")
|
24 |
+
|
25 |
+
input_reading_level = gr.Textbox(label="Input Text Reading Level", visible=False)
|
26 |
+
output_text = gr.Textbox(label="Output Text", visible=False)
|
27 |
+
output_reading_level = gr.Textbox(label="Output Text Reading Level", visible=False)
|
28 |
+
output_text_similarity = gr.Textbox(label="Output Text Similarity to Input Text", visible=False)
|
29 |
|
30 |
+
button1.click(
|
31 |
+
fn=calc_input_reading_level,
|
32 |
+
inputs=input_text1,
|
33 |
+
outputs=input_reading_level
|
34 |
+
)
|
|
|
35 |
|
36 |
+
button2.click(
|
37 |
+
fn=generate_and_analyze_text,
|
38 |
+
inputs=[input_text2, target_level],
|
39 |
+
outputs=[input_reading_level, output_text, output_reading_level, output_text_similarity]
|
40 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
app.launch()
|