ningrumdaud commited on
Commit
8342ba8
·
verified ·
1 Parent(s): d539513

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -192,49 +192,38 @@ def CogMapAnalysis(text):
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)
 
 
192
 
193
  # Create the GUI using the 'gr' library
194
 
 
 
 
 
 
195
  with gr.Blocks() as demo:
196
  with gr.Row():
197
+ gr.Markdown("<h1 style='text-align: center;'><strong>CogMApp</strong></h1>")
198
+ gr.Markdown("<h3 style='text-align: center;'>Generate cognitive maps from text with one click!</h3>")
199
+
200
  with gr.Row():
201
  inputs = gr.Textbox(label="Input", lines=2, placeholder="Enter your text here...")
 
 
 
202
  examples = [
203
  "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.",
204
  "The introduction of new anti-discrimination laws has been driven by an increasing awareness of social injustices and grassroots movements.",
205
  "The weak law enforcement in this country is due to its citizens's ignorance.",
206
  "CogMApp is a tool that lets you create cognitive maps from text."
207
  ]
208
+ examples_dropdown = gr.Dropdown(label="Examples", choices=examples)
209
+ submit_button = gr.Button("Submit")
 
 
 
 
210
 
211
  with gr.Row():
212
+ output = gr.Textbox(label="CogMap", lines=1, placeholder="Generated CogMap will appear here.")
213
+
214
+ with gr.Row():
215
  cogmap_plot = gr.Plot(label="Visualization")
 
 
216
 
217
  with gr.Row():
218
+ flag_notice = gr.Markdown("⚠️ Feel free to flag me if you find any errors. 🙂")
219
 
220
+ with gr.Column():
221
+ gr.Markdown('<p style="text-align: center;">Demo made with ❤ by P.K. Ningrum (2024) | Contact: <a href="https://ningrumdaud.github.io/">https://ningrumdaud.github.io/</a></p>')
222
 
223
+ # Linking the button to execute the function
224
  submit_button.click(CogMapAnalysis, inputs=[inputs], outputs=[output, cogmap_plot])
225
+ examples_dropdown.change(fn=lambda x: inputs.update(x), inputs=[examples_dropdown], outputs=[inputs])
226
 
227
  if __name__ == "__main__":
228
  demo.launch(show_api=False, share=True)
229
+