DHEIVER commited on
Commit
e3a960d
·
verified ·
1 Parent(s): 04f5606

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +181 -144
app.py CHANGED
@@ -108,79 +108,126 @@ def conversation(qa_chain, message, history):
108
  new_history = history + [(message, response_answer)]
109
  return qa_chain, gr.update(value=""), new_history, response_source1, response_source1_page, response_source2, response_source2_page, response_source3, response_source3_page
110
 
 
 
 
111
  def demo():
112
- """Main demo application"""
113
  theme = gr.themes.Default(
114
  primary_hue="indigo",
115
  secondary_hue="blue",
116
  neutral_hue="slate",
117
  )
118
 
119
- with gr.Blocks(theme=theme) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  vector_db = gr.State()
121
  qa_chain = gr.State()
122
 
123
- # Header
124
- gr.HTML(
125
- """
126
- <div style='text-align: center; padding: 20px;'>
127
- <h1 style='color: #1a365d; margin-bottom: 10px;'>MetroAssist AI - Expert in Metrology Report Analysis</h1>
128
- <p style='color: #4a5568; font-size: 1.2em;'>Your intelligent assistant for advanced analysis of metrological documents</p>
129
- </div>
130
- """
131
- )
132
 
133
- # Marketing description
134
- gr.Markdown(
135
- """
136
- ### 🔍 Specialized Metrology Analysis
137
-
138
- MetroAssist AI is a specialized assistant designed to revolutionize metrology report analysis.
139
- Powered by cutting-edge AI technology, it offers:
140
-
141
- * **Precise Analysis**: Detailed interpretation of measurements, calibrations, and compliance
142
- * **Intelligent Contextualization**: Deep understanding of metrological standards and norms
143
- * **Advanced Technical Support**: Assistance in complex instrument and measurement analyses
144
- * **Rapid Processing**: Efficient analysis of multiple technical documents
145
-
146
- ⚠️ **Security Note**: Your documents are processed with complete security. We do not permanently store confidential data.
147
- """
148
- )
149
-
150
- with gr.Row():
151
- with gr.Column(scale=86):
152
- gr.Markdown("### 📥 Step 1: Document Loading and Preparation")
153
- gr.Markdown("Upload your metrology reports for expert analysis.")
154
-
155
- with gr.Row():
156
- document = gr.Files(
157
- label="Upload Metrology Reports (PDF)",
158
- file_count="multiple",
159
- file_types=["pdf"],
160
- interactive=True,
161
- )
162
- with gr.Row():
163
- db_btn = gr.Button("Process Documents")
164
- with gr.Row():
165
- db_progress = gr.Textbox(
166
- value="Waiting for documents...",
167
- label="Status"
168
- )
169
-
170
- gr.Markdown("### 🤖 Analysis Engine Configuration")
171
- gr.Markdown("Select and configure the AI model to best meet your needs.")
172
-
173
- with gr.Row():
174
- llm_btn = gr.Radio(
175
- choices=list_llm_simple,
176
- label="Available AI Models",
177
- value=list_llm_simple[0],
178
- type="index"
179
- )
180
-
181
- with gr.Row():
182
- with gr.Accordion("Advanced Analysis Parameters", open=False):
183
- with gr.Row():
184
  slider_temperature = gr.Slider(
185
  minimum=0.01,
186
  maximum=1.0,
@@ -188,7 +235,6 @@ def demo():
188
  step=0.1,
189
  label="Analysis Precision"
190
  )
191
- with gr.Row():
192
  slider_maxtokens = gr.Slider(
193
  minimum=128,
194
  maximum=9192,
@@ -196,7 +242,6 @@ def demo():
196
  step=128,
197
  label="Response Length"
198
  )
199
- with gr.Row():
200
  slider_topk = gr.Slider(
201
  minimum=1,
202
  maximum=10,
@@ -204,90 +249,82 @@ def demo():
204
  step=1,
205
  label="Analysis Diversity"
206
  )
207
-
208
- with gr.Row():
209
- qachain_btn = gr.Button("Initialize Analysis Assistant")
210
- with gr.Row():
211
- llm_progress = gr.Textbox(
212
- value="Waiting for initialization...",
213
- label="Assistant Status"
214
- )
215
-
216
- with gr.Column(scale=200):
217
- gr.Markdown(
218
- """
219
- ### 💬 Step 2: Expert Consultation and Analysis
220
- Ask questions about your metrology reports. The assistant will provide detailed technical analyses.
221
-
222
- **Suggested questions:**
223
- - Analyze the calibration results of this instrument
224
- - Verify compliance with technical standards
225
- - Identify critical points in measurements
226
- - Compare results with specified limits
227
- - Evaluate measurement uncertainty
228
- - Assess calibration intervals
229
- """
230
- )
231
- chatbot = gr.Chatbot(
232
- height=505,
233
- label="Metrology Analysis"
234
- )
235
-
236
- with gr.Accordion("Source Document References", open=False):
237
- with gr.Row():
238
- doc_source1 = gr.Textbox(
239
- label="Technical Reference 1",
240
- lines=2
241
- )
242
- source1_page = gr.Number(label="Page")
243
- with gr.Row():
244
- doc_source2 = gr.Textbox(
245
- label="Technical Reference 2",
246
- lines=2
247
  )
248
- source2_page = gr.Number(label="Page")
249
- with gr.Row():
250
- doc_source3 = gr.Textbox(
251
- label="Technical Reference 3",
252
- lines=2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  )
254
- source3_page = gr.Number(label="Page")
255
-
256
- with gr.Row():
257
- msg = gr.Textbox(
258
- placeholder="Enter your question about the metrology report...",
259
- label="Your Query"
260
- )
261
- with gr.Row():
262
- submit_btn = gr.Button("Submit Query")
263
- clear_btn = gr.ClearButton(
264
- [msg, chatbot],
265
- value="Clear Conversation"
266
- )
267
-
 
 
 
 
 
 
 
 
268
  # Footer
269
- gr.Markdown(
270
- """
271
- ---
272
- ### ℹ️ About MetroAssist AI
273
-
274
- Developed for metrology professionals, engineers, and technicians who need precise
275
- and reliable analysis of technical documents. Our tool uses advanced AI technology
276
- to provide valuable insights and support decision-making in metrology.
277
-
278
- **Specialized Features:**
279
- - Detailed analysis of calibration certificates
280
- - Interpretation of complex metrological data
281
- - Verification of compliance with technical standards
282
- - Decision support in metrological processes
283
- - Uncertainty analysis and measurement traceability
284
- - Quality control and measurement system analysis
285
-
286
- *Version 1.0 - Updated 2024*
287
- """
288
- )
289
 
290
- # Event handlers
291
  db_btn.click(
292
  initialize_database,
293
  inputs=[document],
 
108
  new_history = history + [(message, response_answer)]
109
  return qa_chain, gr.update(value=""), new_history, response_source1, response_source1_page, response_source2, response_source2_page, response_source3, response_source3_page
110
 
111
+
112
+ # [Previous imports remain the same...]
113
+
114
  def demo():
115
+ """Main demo application with enhanced layout"""
116
  theme = gr.themes.Default(
117
  primary_hue="indigo",
118
  secondary_hue="blue",
119
  neutral_hue="slate",
120
  )
121
 
122
+ # Custom CSS for advanced layout
123
+ custom_css = """
124
+ #app-header {
125
+ text-align: center;
126
+ padding: 2rem;
127
+ background: linear-gradient(to right, #1a365d, #2c5282);
128
+ color: white;
129
+ margin-bottom: 2rem;
130
+ border-radius: 0 0 1rem 1rem;
131
+ }
132
+ #app-header h1 {
133
+ font-size: 2.5rem;
134
+ margin-bottom: 0.5rem;
135
+ color: white;
136
+ }
137
+ #app-header p {
138
+ font-size: 1.2rem;
139
+ opacity: 0.9;
140
+ }
141
+ .container {
142
+ max-width: 1400px;
143
+ margin: 0 auto;
144
+ padding: 0 1rem;
145
+ }
146
+ .features-grid {
147
+ display: grid;
148
+ grid-template-columns: repeat(2, 1fr);
149
+ gap: 1rem;
150
+ margin-bottom: 2rem;
151
+ }
152
+ .feature-card {
153
+ background: #f8fafc;
154
+ padding: 1.5rem;
155
+ border-radius: 0.5rem;
156
+ border: 1px solid #e2e8f0;
157
+ }
158
+ .section-title {
159
+ font-size: 1.5rem;
160
+ color: #1a365d;
161
+ margin-bottom: 1rem;
162
+ padding-bottom: 0.5rem;
163
+ border-bottom: 2px solid #e2e8f0;
164
+ }
165
+ .control-panel {
166
+ background: #f8fafc;
167
+ padding: 1.5rem;
168
+ border-radius: 0.5rem;
169
+ margin-bottom: 1rem;
170
+ }
171
+ .chat-container {
172
+ background: white;
173
+ border-radius: 0.5rem;
174
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
175
+ }
176
+ .reference-panel {
177
+ background: #f8fafc;
178
+ padding: 1rem;
179
+ border-radius: 0.5rem;
180
+ margin-top: 1rem;
181
+ }
182
+ """
183
+
184
+ with gr.Blocks(theme=theme, css=custom_css) as demo:
185
  vector_db = gr.State()
186
  qa_chain = gr.State()
187
 
188
+ # Enhanced Header
189
+ with gr.Row(elem_id="app-header"):
190
+ with gr.Column():
191
+ gr.HTML(
192
+ """
193
+ <h1>MetroAssist AI</h1>
194
+ <p>Expert System for Metrology Report Analysis</p>
195
+ """
196
+ )
197
 
198
+ # Main Content Container
199
+ with gr.Row(equal_height=True):
200
+ # Left Column - Control Panel
201
+ with gr.Column(scale=1):
202
+ with gr.Group(visible=True) as control_panel:
203
+ gr.Markdown("## Document Processing", elem_classes="section-title")
204
+
205
+ # File Upload Section
206
+ with gr.Box(elem_classes="control-panel"):
207
+ gr.Markdown("### 📄 Upload Documents")
208
+ document = gr.Files(
209
+ label="Metrology Reports (PDF)",
210
+ file_count="multiple",
211
+ file_types=["pdf"],
212
+ )
213
+ db_btn = gr.Button("Process Documents", elem_classes="primary-btn")
214
+ db_progress = gr.Textbox(
215
+ value="Ready for documents",
216
+ label="Processing Status",
217
+ )
218
+
219
+ # Model Selection Section
220
+ with gr.Box(elem_classes="control-panel"):
221
+ gr.Markdown("### 🤖 Model Configuration")
222
+ llm_btn = gr.Radio(
223
+ choices=list_llm_simple,
224
+ label="Select AI Model",
225
+ value=list_llm_simple[0],
226
+ type="index"
227
+ )
228
+
229
+ # Advanced Parameters
230
+ with gr.Accordion("Advanced Settings", open=False):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
231
  slider_temperature = gr.Slider(
232
  minimum=0.01,
233
  maximum=1.0,
 
235
  step=0.1,
236
  label="Analysis Precision"
237
  )
 
238
  slider_maxtokens = gr.Slider(
239
  minimum=128,
240
  maximum=9192,
 
242
  step=128,
243
  label="Response Length"
244
  )
 
245
  slider_topk = gr.Slider(
246
  minimum=1,
247
  maximum=10,
 
249
  step=1,
250
  label="Analysis Diversity"
251
  )
252
+
253
+ qachain_btn = gr.Button("Initialize Assistant")
254
+ llm_progress = gr.Textbox(
255
+ value="Not initialized",
256
+ label="Assistant Status"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  )
258
+
259
+ # Right Column - Chat Interface
260
+ with gr.Column(scale=2):
261
+ with gr.Group() as chat_interface:
262
+ gr.Markdown("## Interactive Analysis", elem_classes="section-title")
263
+
264
+ # Feature Cards
265
+ with gr.Row(equal_height=True) as feature_grid:
266
+ with gr.Column():
267
+ gr.Markdown(
268
+ """
269
+ ### 📊 Capabilities
270
+ - Calibration Analysis
271
+ - Standards Compliance
272
+ - Uncertainty Evaluation
273
+ """
274
+ )
275
+ with gr.Column():
276
+ gr.Markdown(
277
+ """
278
+ ### 💡 Best Practices
279
+ - Ask specific questions
280
+ - Include measurement context
281
+ - Specify standards
282
+ """
283
+ )
284
+
285
+ # Chat Interface
286
+ with gr.Box(elem_classes="chat-container"):
287
+ chatbot = gr.Chatbot(
288
+ height=400,
289
+ label="Analysis Conversation"
290
  )
291
+ with gr.Row():
292
+ msg = gr.Textbox(
293
+ placeholder="Ask about your metrology report...",
294
+ label="Query",
295
+ scale=4
296
+ )
297
+ submit_btn = gr.Button("Send")
298
+ clear_btn = gr.ClearButton([msg, chatbot], value="Clear")
299
+
300
+ # Reference Panel
301
+ with gr.Accordion("Document References", open=False, elem_classes="reference-panel"):
302
+ with gr.Row():
303
+ with gr.Column():
304
+ doc_source1 = gr.Textbox(label="Reference 1", lines=2)
305
+ source1_page = gr.Number(label="Page")
306
+ with gr.Column():
307
+ doc_source2 = gr.Textbox(label="Reference 2", lines=2)
308
+ source2_page = gr.Number(label="Page")
309
+ with gr.Column():
310
+ doc_source3 = gr.Textbox(label="Reference 3", lines=2)
311
+ source3_page = gr.Number(label="Page")
312
+
313
  # Footer
314
+ with gr.Row():
315
+ gr.Markdown(
316
+ """
317
+ ---
318
+ ### About MetroAssist AI
319
+
320
+ A specialized tool for metrology professionals, providing advanced analysis
321
+ of calibration certificates, measurement data, and technical standards compliance.
322
+
323
+ **Version 1.0** | © 2024 MetroAssist AI
324
+ """
325
+ )
 
 
 
 
 
 
 
 
326
 
327
+ # Event Handlers
328
  db_btn.click(
329
  initialize_database,
330
  inputs=[document],