Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -192,51 +192,49 @@ def CogMapAnalysis(text):
|
|
192 |
|
193 |
# Create the GUI using the 'gr' library
|
194 |
|
195 |
-
def handle_flag(
|
196 |
# Placeholder for handling flags; log to a file or send to an endpoint
|
197 |
-
print(f"Flagged
|
198 |
return "Thank you for your feedback!"
|
199 |
|
200 |
with gr.Blocks() as demo:
|
201 |
with gr.Row():
|
202 |
-
gr.Markdown('<div style="text-align: center;"><h1><strong>CogMApp</strong></h1></div>
|
|
|
203 |
|
204 |
with gr.Row():
|
205 |
-
|
206 |
-
|
207 |
-
submit_button = gr.Button("Submit")
|
208 |
-
with gr.Column():
|
209 |
-
examples = [
|
210 |
-
"Public support for anti-discrimination laws and the movement to support immigrants grew due to the impact of getting widespread education on social justice issues.",
|
211 |
-
"The introduction of new anti-discrimination laws has been driven by an increasing awareness of social injustices and grassroots movements.",
|
212 |
-
"The weak law enforcement in this country is due to its citizens's ignorance.",
|
213 |
-
"CogMApp is a tool that lets you create cognitive maps from text."
|
214 |
-
]
|
215 |
-
example_dropdown = gr.Dropdown(label="Examples", choices=examples, type="index")
|
216 |
-
load_example_button = gr.Button("Load Example")
|
217 |
|
218 |
with gr.Row():
|
219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
cogmap_plot = gr.Plot(label="Visualization")
|
221 |
flag_description = gr.Textbox(label="Describe the issue", lines=2, placeholder="What's wrong?")
|
222 |
flag_button = gr.Button("Flag Issue")
|
223 |
-
|
224 |
with gr.Row():
|
225 |
gr.Markdown("⚠️ Feel free to flag me if you find any errors. :)")
|
226 |
|
227 |
with gr.Row():
|
228 |
gr.Markdown('<p style="text-align: center; ">Demo made with ❤ by P.K. Ningrum (2024) | Contact: https://ningrumdaud.github.io/ </p>')
|
229 |
|
230 |
-
#
|
231 |
-
def load_example(example_index):
|
232 |
-
inputs.value = examples[example_index]
|
233 |
-
|
234 |
-
# Link functions to interface elements
|
235 |
-
example_dropdown.change(load_example, inputs=[example_dropdown], outputs=[inputs])
|
236 |
submit_button.click(CogMapAnalysis, inputs=[inputs], outputs=[output, cogmap_plot])
|
237 |
-
flag_button.click(handle_flag, inputs=[
|
238 |
|
239 |
if __name__ == "__main__":
|
240 |
demo.launch(show_api=False, share=True)
|
241 |
-
|
242 |
-
|
|
|
192 |
|
193 |
# Create the GUI using the 'gr' library
|
194 |
|
195 |
+
def handle_flag(description):
|
196 |
# Placeholder for handling flags; log to a file or send to an endpoint
|
197 |
+
print(f"Flagged: {description}")
|
198 |
return "Thank you for your feedback!"
|
199 |
|
200 |
with gr.Blocks() as demo:
|
201 |
with gr.Row():
|
202 |
+
gr.Markdown('<div style="text-align: center;"><h1><strong>CogMApp</strong></h1></div>')
|
203 |
+
gr.Markdown('<div style="text-align: center;"><h3>Generate cognitive maps from text with one click!</h3></div>')
|
204 |
|
205 |
with gr.Row():
|
206 |
+
inputs = gr.Textbox(label="Input", lines=2, placeholder="Enter your text here...")
|
207 |
+
submit_button = gr.Button("Submit")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
|
209 |
with gr.Row():
|
210 |
+
examples = [
|
211 |
+
"Public support for anti-discrimination laws and the movement to support immigrants grew due to the impact of getting widespread education on social justice issues.",
|
212 |
+
"The introduction of new anti-discrimination laws has been driven by an increasing awareness of social injustices and grassroots movements.",
|
213 |
+
"The weak law enforcement in this country is due to its citizens's ignorance.",
|
214 |
+
"CogMApp is a tool that lets you create cognitive maps from text."
|
215 |
+
]
|
216 |
+
for example in examples:
|
217 |
+
gr.Button(example, elem_id=f"example-{examples.index(example)}").click(
|
218 |
+
lambda x, btn=example: x,
|
219 |
+
inputs=None,
|
220 |
+
outputs=inputs
|
221 |
+
)
|
222 |
+
|
223 |
+
with gr.Row():
|
224 |
+
output = gr.Textbox(label="CogMap", lines=1, placeholder="Generated CogMap here")
|
225 |
cogmap_plot = gr.Plot(label="Visualization")
|
226 |
flag_description = gr.Textbox(label="Describe the issue", lines=2, placeholder="What's wrong?")
|
227 |
flag_button = gr.Button("Flag Issue")
|
228 |
+
|
229 |
with gr.Row():
|
230 |
gr.Markdown("⚠️ Feel free to flag me if you find any errors. :)")
|
231 |
|
232 |
with gr.Row():
|
233 |
gr.Markdown('<p style="text-align: center; ">Demo made with ❤ by P.K. Ningrum (2024) | Contact: https://ningrumdaud.github.io/ </p>')
|
234 |
|
235 |
+
# Connect the interface logic
|
|
|
|
|
|
|
|
|
|
|
236 |
submit_button.click(CogMapAnalysis, inputs=[inputs], outputs=[output, cogmap_plot])
|
237 |
+
flag_button.click(handle_flag, inputs=[flag_description], outputs=[])
|
238 |
|
239 |
if __name__ == "__main__":
|
240 |
demo.launch(show_api=False, share=True)
|
|
|
|