cptcrk commited on
Commit
ed16904
Β·
verified Β·
1 Parent(s): 749386f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -65,14 +65,13 @@ def analyze_multilingual_sentences(text):
65
 
66
  return output, fig
67
 
68
- # Voorbeeldzinnen bovenaan
69
  example_sentences_top = [
70
  "I just won the lottery!",
71
  "My phone battery died in the middle of an important call.",
72
  "This weather is so boring."
73
  ]
74
 
75
- # Extra voorbeeldzinnen onderaan
76
  example_sentences_bottom = [
77
  "I woke up at 5 AM and went for a run.",
78
  "This is the worst movie I have ever seen.",
@@ -82,9 +81,11 @@ example_sentences_bottom = [
82
  "I finally finished my project, time to celebrate!"
83
  ]
84
 
85
- # Functie om voorbeeldzinnen in het invoerveld te zetten
86
- def fill_example(example):
87
- return gr.update(value=example)
 
 
88
 
89
  # Gradio-interface met duidelijke instructies en styling
90
  with gr.Blocks() as demo:
@@ -97,30 +98,31 @@ with gr.Blocks() as demo:
97
  """
98
  )
99
 
100
- # Voorbeeldzinnen bovenaan
101
- gr.Markdown("<h3>πŸ’‘ Try These Sentences:</h3>")
102
- with gr.Row():
103
- for example in example_sentences_top:
104
- gr.Button(example).click(fill_example, inputs=[], outputs=gr.Textbox(), queue=False)
105
-
106
  input_box = gr.Textbox(
107
  lines=5,
108
  placeholder="Hey there! Drop some sentences (one per line) and get instant sentiment vibesβ€”positive, neutral, or negative...",
109
  label="Enter Sentences"
110
  )
111
-
112
- output_box = gr.HTML(label="Results")
113
- plot_box = gr.Plot(label="Sentiment Distribution")
 
 
 
114
 
115
  analyze_button = gr.Button("Tell me how I feel", elem_id="analyze-btn")
116
- analyze_button.click(analyze_multilingual_sentences, inputs=input_box, outputs=[output_box, plot_box])
 
117
 
118
- gr.Markdown("<h3>πŸ’‘ Try More Sentences:</h3>")
119
 
 
 
120
  with gr.Row():
121
  for example in example_sentences_bottom:
122
- gr.Button(example).click(fill_example, inputs=[], outputs=input_box, queue=False)
123
 
124
  # Start de app
125
  demo.launch()
126
 
 
 
65
 
66
  return output, fig
67
 
68
+ # Voorbeeldzinnen
69
  example_sentences_top = [
70
  "I just won the lottery!",
71
  "My phone battery died in the middle of an important call.",
72
  "This weather is so boring."
73
  ]
74
 
 
75
  example_sentences_bottom = [
76
  "I woke up at 5 AM and went for a run.",
77
  "This is the worst movie I have ever seen.",
 
81
  "I finally finished my project, time to celebrate!"
82
  ]
83
 
84
+ # Functie om een voorbeeldzin toe te voegen aan het invoerveld zonder te overschrijven
85
+ def add_example_text(current_text, example):
86
+ if current_text.strip():
87
+ return f"{current_text}\n{example}"
88
+ return example
89
 
90
  # Gradio-interface met duidelijke instructies en styling
91
  with gr.Blocks() as demo:
 
98
  """
99
  )
100
 
 
 
 
 
 
 
101
  input_box = gr.Textbox(
102
  lines=5,
103
  placeholder="Hey there! Drop some sentences (one per line) and get instant sentiment vibesβ€”positive, neutral, or negative...",
104
  label="Enter Sentences"
105
  )
106
+
107
+ # Voorbeeldzinnen bovenaan (toevoegen aan invoerveld)
108
+ gr.Markdown("<h3>πŸ’‘ Try These Sentences:</h3>")
109
+ with gr.Row():
110
+ for example in example_sentences_top:
111
+ gr.Button(example).click(add_example_text, inputs=[input_box, gr.Textbox(value=example, visible=False)], outputs=input_box, queue=False)
112
 
113
  analyze_button = gr.Button("Tell me how I feel", elem_id="analyze-btn")
114
+ output_box = gr.HTML(label="Results")
115
+ plot_box = gr.Plot(label="Sentiment Distribution", visible=False)
116
 
117
+ analyze_button.click(analyze_multilingual_sentences, inputs=input_box, outputs=[output_box, plot_box])
118
 
119
+ # Voorbeeldzinnen onderaan (toevoegen aan invoerveld)
120
+ gr.Markdown("<h3>πŸ’‘ Try More Sentences:</h3>")
121
  with gr.Row():
122
  for example in example_sentences_bottom:
123
+ gr.Button(example).click(add_example_text, inputs=[input_box, gr.Textbox(value=example, visible=False)], outputs=input_box, queue=False)
124
 
125
  # Start de app
126
  demo.launch()
127
 
128
+