ningrumdaud commited on
Commit
7ca5735
·
verified ·
1 Parent(s): 5aa0920

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -23
app.py CHANGED
@@ -191,36 +191,39 @@ def CogMapAnalysis(text):
191
 
192
  # Create the GUI using the 'gr' library
193
  with gr.Blocks() as demo:
194
- gr.Markdown('<div style="text-align: center;"><h1><strong>CogMApp</strong></h1></div> <div style="text-align: center;"><h3>Generate cognitive maps from text with one click!</h3></div>')
 
195
 
196
  with gr.Row():
197
  with gr.Column():
198
- inputs = gr.Textbox(label="Input Text", lines=4, placeholder="Enter your text here...")
199
- output = gr.Textbox(label="CogMap Output", lines=4, placeholder="Processed output appears here...", interactive=False)
200
  submit_button = gr.Button("Submit")
201
  with gr.Column():
202
- cogmap_plot = gr.Plot(label="Visualization")
203
- gr.Markdown("⚠️ Feel free to flag me if you find any errors. 🙂")
204
-
205
- examples = [
206
- "Public support for anti-discrimination laws and the movement to support immigrants grew due to the impact of widespread education on social justice issues.",
207
- "The introduction of new anti-discrimination laws has been driven by an increasing awareness of social injustices and grassroots movements.",
208
- "The weak enforcement in this country is due to its citizens' ignorance.",
209
- "CogMApp is a tool that lets you create cognitive maps from text."
210
- ]
211
-
212
- def update_output(input_text):
213
- return CogMapAnalysis(input_text)
214
-
215
- submit_button.click(
216
- fn=update_output,
217
- inputs=inputs,
218
- outputs=[output, cogmap_plot]
219
- )
220
 
221
- inputs.add_examples(examples, fn=CogMapAnalysis)
 
 
 
 
 
222
 
223
- 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>')
 
224
 
225
  if __name__ == "__main__":
226
  demo.launch(show_api=False, share=True)
 
191
 
192
  # Create the GUI using the 'gr' library
193
  with gr.Blocks() as demo:
194
+ with gr.Row():
195
+ gr.Markdown('<div style="text-align: center;"><h1><strong>CogMApp</strong></h1></div> <div style="text-align: center;"><h3>Generate cognitive maps from text with one click!</h3></div>')
196
 
197
  with gr.Row():
198
  with gr.Column():
199
+ inputs = gr.Textbox(label="Input", lines=2, placeholder="Enter your text here...")
 
200
  submit_button = gr.Button("Submit")
201
  with gr.Column():
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
+ example_dropdown = gr.Dropdown(label="Examples", choices=examples, type="index")
209
+ load_example_button = gr.Button("Load Example")
210
+
211
+ with gr.Row():
212
+ output = gr.Textbox(label="CogMApp", lines=1, placeholder=" ")
213
+ cogmap_plot = gr.Plot(label="Visualization")
214
+
215
+ with gr.Row():
216
+ gr.Markdown("⚠️ Feel free to flag me if you find any errors. :)")
 
 
 
217
 
218
+ with gr.Row():
219
+ gr.Markdown('<p style="text-align: center; ">Demo made with ❤ by P.K. Ningrum (2024) | Contact: https://ningrumdaud.github.io/ </p>')
220
+
221
+ # Function to handle loading examples
222
+ def load_example(example_index):
223
+ inputs.value = examples[example_index]
224
 
225
+ example_dropdown.change(load_example, inputs=[example_dropdown], outputs=[inputs])
226
+ submit_button.click(CogMapAnalysis, inputs=[inputs], outputs=[output, cogmap_plot])
227
 
228
  if __name__ == "__main__":
229
  demo.launch(show_api=False, share=True)