Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -67,64 +67,61 @@ def analyze_text(input_text, input_type, tasks, progress=gr.Progress()):
|
|
67 |
return original_text, summary, sentiment, ", ".join(topics)
|
68 |
|
69 |
def create_interface():
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
inputs=[input_type, text_input, url_input, file_input, tasks_checkboxes, submit_button],
|
126 |
-
outputs=[interface, progress_bar]
|
127 |
-
)
|
128 |
|
129 |
if __name__ == "__main__":
|
130 |
create_interface().launch()
|
|
|
67 |
return original_text, summary, sentiment, ", ".join(topics)
|
68 |
|
69 |
def create_interface():
|
70 |
+
with gr.Blocks(title="Text Analysis App") as interface:
|
71 |
+
input_type = gr.Dropdown(["Text", "URL", "File"], label="Input Type")
|
72 |
+
text_input = gr.Textbox(visible=False)
|
73 |
+
url_input = gr.Textbox(visible=False)
|
74 |
+
file_input = gr.File(visible=False)
|
75 |
+
|
76 |
+
tasks_checkboxes = gr.CheckboxGroup(["Summarization", "Sentiment Analysis", "Topic Detection"], label="Analysis Tasks")
|
77 |
+
|
78 |
+
submit_button = gr.Button("Analyze")
|
79 |
+
progress_bar = gr.Progress()
|
80 |
+
|
81 |
+
original_text_output = gr.Textbox(label="Original Text")
|
82 |
+
summary_output = gr.Textbox(label="Summary")
|
83 |
+
sentiment_output = gr.Textbox(label="Sentiment")
|
84 |
+
topics_output = gr.Textbox(label="Topics")
|
85 |
+
|
86 |
+
def update_input_visibility(input_type):
|
87 |
+
text_input.visible = input_type == "Text"
|
88 |
+
url_input.visible = input_type == "URL"
|
89 |
+
file_input.visible = input_type == "File"
|
90 |
+
|
91 |
+
input_type.change(update_input_visibility, inputs=input_type)
|
92 |
+
|
93 |
+
def process_input(input_type, text, url, file, tasks):
|
94 |
+
if input_type == "Text":
|
95 |
+
input_value = text
|
96 |
+
elif input_type == "URL":
|
97 |
+
input_value = url
|
98 |
+
else:
|
99 |
+
input_value = file
|
100 |
+
|
101 |
+
try:
|
102 |
+
original_text, summary, sentiment, topics = analyze_text(input_value, input_type, tasks, progress_bar)
|
103 |
+
except Exception as e:
|
104 |
+
original_text = f"Error: {str(e)}"
|
105 |
+
summary, sentiment, topics = "", "", ""
|
106 |
+
|
107 |
+
return original_text, summary, sentiment, topics
|
108 |
+
|
109 |
+
submit_button.click(
|
110 |
+
fn=process_input,
|
111 |
+
inputs=[input_type, text_input, url_input, file_input, tasks_checkboxes],
|
112 |
+
outputs=[original_text_output, summary_output, sentiment_output, topics_output]
|
113 |
+
)
|
114 |
+
|
115 |
+
interface.set_layout(
|
116 |
+
gr.Tabs([
|
117 |
+
gr.Tab(original_text_output, label="Original Text"),
|
118 |
+
gr.Tab(summary_output, label="Summary"),
|
119 |
+
gr.Tab(sentiment_output, label="Sentiment"),
|
120 |
+
gr.Tab(topics_output, label="Topics")
|
121 |
+
])
|
122 |
+
)
|
123 |
+
|
124 |
+
return interface
|
|
|
|
|
|
|
125 |
|
126 |
if __name__ == "__main__":
|
127 |
create_interface().launch()
|