urchade commited on
Commit
b9fed37
Β·
verified Β·
1 Parent(s): f6607f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +133 -17
app.py CHANGED
@@ -75,6 +75,126 @@ header.brand .subtitle {
75
  }
76
  """
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"), css=custom_css) as demo:
79
  # Header
80
  gr.HTML(
@@ -91,11 +211,12 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"),
91
  with gr.TabItem("πŸ” Named Entity Recognition"):
92
  with gr.Row(elem_classes="card"):
93
  with gr.Column(scale=2):
94
- txt1 = gr.Textbox(label="Input Text", lines=5, placeholder="Enter text to extract entities...")
95
- types1 = gr.Textbox(label="Entity Types (CSV)", value="person, organization, location, date, title, topic")
96
  with gr.Accordion("Optional Descriptions", open=False):
97
- desc1 = gr.Textbox(lines=3, placeholder="person: Full name\norganization: Companies\n...")
98
  btn1 = gr.Button("Extract Entities", variant="primary")
 
99
  with gr.Column(scale=1):
100
  out1 = gr.Code(language="json", label="Results", lines=8)
101
  btn1.click(run_ner, inputs=[txt1, types1, desc1], outputs=out1)
@@ -104,13 +225,14 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"),
104
  with gr.TabItem("πŸ“ Text Classification"):
105
  with gr.Row(elem_classes="card"):
106
  with gr.Column(scale=2):
107
- txt2 = gr.Textbox(label="Input Text", lines=5, placeholder="Enter text to classify...")
108
- task2 = gr.Textbox(label="Task Name", value="sentiment_analysis")
109
- labs2 = gr.Textbox(label="Labels (CSV)", value="positive, negative, neutral")
110
  with gr.Accordion("Optional Label Descriptions", open=False):
111
- desc2 = gr.Textbox(lines=3, placeholder="positive: Positive sentiment\n...")
112
- multi2 = gr.Checkbox(label="Multi-label?", value=False)
113
  btn2 = gr.Button("Classify Text", variant="primary")
 
114
  with gr.Column(scale=1):
115
  out2 = gr.Code(language="json", label="Results", lines=8)
116
  btn2.click(run_class, inputs=[txt2, task2, labs2, desc2, multi2], outputs=out2)
@@ -119,16 +241,10 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"),
119
  with gr.TabItem("πŸ“ Structure Extraction"):
120
  with gr.Row(elem_classes="card"):
121
  with gr.Column(scale=2):
122
- txt3 = gr.Textbox(label="Input Text", lines=5, placeholder="Enter text for structure extraction...")
123
- struct3 = gr.Code(language="json", label="Schema (JSON)", lines=8, value=json.dumps({
124
- "product": [
125
- "name::str::Product name and model",
126
- "price::str::Product price",
127
- "features::list::Key features",
128
- "category::str::Product category"
129
- ]
130
- }, indent=2))
131
  btn3 = gr.Button("Extract Structure", variant="primary")
 
132
  with gr.Column(scale=1):
133
  out3 = gr.Code(language="json", label="Results", lines=8)
134
  btn3.click(run_struct, inputs=[txt3, struct3], outputs=out3)
 
75
  }
76
  """
77
 
78
+ # Pre-made examples for each task (5 per tab)
79
+ ner_examples = [
80
+ [
81
+ "Barack Obama visited Berlin in July 2013.",
82
+ "person,location,date",
83
+ "person: Full name\nlocation: City\ndate: Month and year"
84
+ ],
85
+ [
86
+ "Apple released the iPhone 13 on September 14, 2021.",
87
+ "organization,product,date",
88
+ "organization: Company name\nproduct: Device name\ndate: Full date"
89
+ ],
90
+ [
91
+ "Elon Musk announced Tesla's new Roadster at the LA Auto Show.",
92
+ "person,organization,event,location",
93
+ "person: Full name\norganization: Company name\nevent: Conference or show\nlocation: Venue"
94
+ ],
95
+ [
96
+ "The UEFA Champions League Final takes place in Istanbul this year.",
97
+ "event,location,date",
98
+ "event: Sports event\nlocation: City\ndate: Year"
99
+ ],
100
+ [
101
+ "Microsoft acquired GitHub in 2018 for $7.5 billion.",
102
+ "organization,organization,date,price",
103
+ "organization: Company name\ndate: Year\nprice: Acquisition value"
104
+ ]
105
+ ]
106
+
107
+ class_examples = [
108
+ [
109
+ "The movie was a thrilling experience with stunning visuals.",
110
+ "sentiment",
111
+ "positive,negative,neutral",
112
+ "positive: Positive sentiment\nnegative: Negative sentiment\nneutral: Mixed or neutral",
113
+ False
114
+ ],
115
+ [
116
+ "Our Q1 results were disappointing, with sales down 10%.",
117
+ "financial_sentiment",
118
+ "positive,negative,neutral",
119
+ "positive: Gains\nnegative: Losses\nneutral: Flat",
120
+ False
121
+ ],
122
+ [
123
+ "I love the new interface but dislike the slow loading time.",
124
+ "feedback",
125
+ "praise,complaint,suggestion",
126
+ "praise: Positive feedback\ncomplaint: Negative feedback\nsuggestion: Improvement ideas",
127
+ True
128
+ ],
129
+ [
130
+ "The product meets expectations but could use more features.",
131
+ "review",
132
+ "positive,negative",
133
+ "positive: Meets expectations\nnegative: Lacking",
134
+ False
135
+ ],
136
+ [
137
+ "Customer support was helpful, though response times were slow.",
138
+ "support_sentiment",
139
+ "positive,negative,neutral",
140
+ "positive: Helpful support\nnegative: Unhelpful support\nneutral: Mixed experiences",
141
+ True
142
+ ]
143
+ ]
144
+
145
+ struct_examples = [
146
+ [
147
+ "The iPad Pro comes with an M1 chip, 8GB RAM, 256GB storage, and a 12.9-inch display.",
148
+ json.dumps({
149
+ "device": [
150
+ "name::str::Model name",
151
+ "specs::list::Hardware specifications",
152
+ "price::str::Device cost"
153
+ ]
154
+ }, indent=2)
155
+ ],
156
+ [
157
+ "Plan: Write report (Due: May 10), Review code (Due: May 15), Deploy (Due: May 20)",
158
+ json.dumps({
159
+ "tasks": [
160
+ "title::str::Task title",
161
+ "due_date::str::Due date"
162
+ ]
163
+ }, indent=2)
164
+ ],
165
+ [
166
+ "Product: Coffee Mug; Price: $12; Features: ceramic, dishwasher-safe, 12oz capacity.",
167
+ json.dumps({
168
+ "product": [
169
+ "name::str::Product name",
170
+ "price::str::Product price",
171
+ "features::list::Product features"
172
+ ]
173
+ }, indent=2)
174
+ ],
175
+ [
176
+ "Event: AI Conference; Date: August 22, 2025; Location: Paris; Topics: ML, Ethics, Robotics.",
177
+ json.dumps({
178
+ "event": [
179
+ "name::str::Event name",
180
+ "date::str::Event date",
181
+ "location::str::Event location",
182
+ "topics::list::Covered topics"
183
+ ]
184
+ }, indent=2)
185
+ ],
186
+ [
187
+ "Recipe: Pancakes; Ingredients: flour, eggs, milk; Steps: mix, cook, serve.",
188
+ json.dumps({
189
+ "recipe": [
190
+ "title::str::Recipe title",
191
+ "ingredients::list::List of ingredients",
192
+ "steps::list::Preparation steps"
193
+ ]
194
+ }, indent=2)
195
+ ]
196
+ ]
197
+
198
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="purple", secondary_hue="blue"), css=custom_css) as demo:
199
  # Header
200
  gr.HTML(
 
211
  with gr.TabItem("πŸ” Named Entity Recognition"):
212
  with gr.Row(elem_classes="card"):
213
  with gr.Column(scale=2):
214
+ txt1 = gr.Textbox(label="Input Text", lines=5)
215
+ types1 = gr.Textbox(label="Entity Types (CSV)")
216
  with gr.Accordion("Optional Descriptions", open=False):
217
+ desc1 = gr.Textbox(lines=3)
218
  btn1 = gr.Button("Extract Entities", variant="primary")
219
+ gr.Examples(examples=ner_examples, inputs=[txt1, types1, desc1], outputs=None, fn=lambda *args: None, cache_examples=False)
220
  with gr.Column(scale=1):
221
  out1 = gr.Code(language="json", label="Results", lines=8)
222
  btn1.click(run_ner, inputs=[txt1, types1, desc1], outputs=out1)
 
225
  with gr.TabItem("πŸ“ Text Classification"):
226
  with gr.Row(elem_classes="card"):
227
  with gr.Column(scale=2):
228
+ txt2 = gr.Textbox(label="Input Text", lines=5)
229
+ task2 = gr.Textbox(label="Task Name")
230
+ labs2 = gr.Textbox(label="Labels (CSV)")
231
  with gr.Accordion("Optional Label Descriptions", open=False):
232
+ desc2 = gr.Textbox(lines=3)
233
+ multi2 = gr.Checkbox(label="Multi-label?")
234
  btn2 = gr.Button("Classify Text", variant="primary")
235
+ gr.Examples(examples=class_examples, inputs=[txt2, task2, labs2, desc2, multi2], outputs=None, fn=lambda *args: None, cache_examples=False)
236
  with gr.Column(scale=1):
237
  out2 = gr.Code(language="json", label="Results", lines=8)
238
  btn2.click(run_class, inputs=[txt2, task2, labs2, desc2, multi2], outputs=out2)
 
241
  with gr.TabItem("πŸ“ Structure Extraction"):
242
  with gr.Row(elem_classes="card"):
243
  with gr.Column(scale=2):
244
+ txt3 = gr.Textbox(label="Input Text", lines=5)
245
+ struct3 = gr.Code(language="json", label="Schema (JSON)", lines=8)
 
 
 
 
 
 
 
246
  btn3 = gr.Button("Extract Structure", variant="primary")
247
+ gr.Examples(examples=struct_examples, inputs=[txt3, struct3], outputs=None, fn=lambda *args: None, cache_examples=False)
248
  with gr.Column(scale=1):
249
  out3 = gr.Code(language="json", label="Results", lines=8)
250
  btn3.click(run_struct, inputs=[txt3, struct3], outputs=out3)