datasaur-dev commited on
Commit
ec922d3
·
verified ·
1 Parent(s): 209a467

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -7
app.py CHANGED
@@ -30,12 +30,12 @@ def analyze_wod(file_obj, wod_type):
30
  if wod_type == "-- WOD type --" or wod_type is None:
31
  # Show warning dialog and return empty DataFrame
32
  gr.Warning("Please select a WOD type first!")
33
- return pd.DataFrame()
34
 
35
  # Check if file is uploaded
36
  if file_obj is None:
37
  gr.Warning("Please upload a PDF file first!")
38
- return pd.DataFrame()
39
 
40
  print(f"Analyzing '{file_obj.name}' (Type: {wod_type})...")
41
 
@@ -53,6 +53,7 @@ def analyze_wod(file_obj, wod_type):
53
 
54
  # Process the document using the API
55
  api_response = process_wod_document(temp_file_path, wod_type)
 
56
  # api_response = json.loads(output_test)
57
 
58
  # Clean up temporary file if we created one
@@ -63,7 +64,7 @@ def analyze_wod(file_obj, wod_type):
63
  if api_response.get("status") != "success":
64
  error_msg = api_response.get("message", "Unknown error occurred")
65
  gr.Error(f"API Error: {error_msg}")
66
- return pd.DataFrame()
67
 
68
  # Parse the API response
69
  results = api_response.get("results", {})
@@ -92,17 +93,20 @@ def analyze_wod(file_obj, wod_type):
92
  "Status": statuses
93
  })
94
 
95
- # Show success message with prediction
96
  prediction = results.get("prediction", "Unknown")
97
  gr.Info(f"Analysis completed! Overall prediction: {prediction}")
98
 
99
- return df
 
 
 
100
 
101
  except Exception as e:
102
  error_msg = f"Error processing document: {str(e)}"
103
  print(error_msg)
104
  gr.Error(error_msg)
105
- return pd.DataFrame()
106
 
107
  # --- Gradio User Interface Definition ---
108
  # Using gr.Blocks() for a custom layout that matches the elegant design.
@@ -140,6 +144,9 @@ with gr.Blocks(
140
  gr.Markdown("---")
141
  gr.Markdown("## Results")
142
 
 
 
 
143
  # DataFrame to display the output, with styling for the 'Status' column
144
  results_output = gr.DataFrame(
145
  headers=["Requirement", "Reason", "Status"],
@@ -154,7 +161,7 @@ with gr.Blocks(
154
  analyze_btn.click(
155
  fn=analyze_wod,
156
  inputs=[file_input, type_input],
157
- outputs=[results_output]
158
  )
159
 
160
  # --- Launch the Application with Authentication ---
 
30
  if wod_type == "-- WOD type --" or wod_type is None:
31
  # Show warning dialog and return empty DataFrame
32
  gr.Warning("Please select a WOD type first!")
33
+ return "", pd.DataFrame()
34
 
35
  # Check if file is uploaded
36
  if file_obj is None:
37
  gr.Warning("Please upload a PDF file first!")
38
+ return "", pd.DataFrame()
39
 
40
  print(f"Analyzing '{file_obj.name}' (Type: {wod_type})...")
41
 
 
53
 
54
  # Process the document using the API
55
  api_response = process_wod_document(temp_file_path, wod_type)
56
+
57
  # api_response = json.loads(output_test)
58
 
59
  # Clean up temporary file if we created one
 
64
  if api_response.get("status") != "success":
65
  error_msg = api_response.get("message", "Unknown error occurred")
66
  gr.Error(f"API Error: {error_msg}")
67
+ return "", pd.DataFrame()
68
 
69
  # Parse the API response
70
  results = api_response.get("results", {})
 
93
  "Status": statuses
94
  })
95
 
96
+ # Get prediction for display
97
  prediction = results.get("prediction", "Unknown")
98
  gr.Info(f"Analysis completed! Overall prediction: {prediction}")
99
 
100
+ # Format prediction as centered H1 for display
101
+ prediction_display = f"<h1 style='text-align: center; color: #1f77b4;'>{prediction}</h1>" if prediction != "Unknown" else ""
102
+
103
+ return prediction_display, df
104
 
105
  except Exception as e:
106
  error_msg = f"Error processing document: {str(e)}"
107
  print(error_msg)
108
  gr.Error(error_msg)
109
+ return "", pd.DataFrame()
110
 
111
  # --- Gradio User Interface Definition ---
112
  # Using gr.Blocks() for a custom layout that matches the elegant design.
 
144
  gr.Markdown("---")
145
  gr.Markdown("## Results")
146
 
147
+ # Prediction display (centered H1)
148
+ prediction_output = gr.Markdown(value="", visible=True)
149
+
150
  # DataFrame to display the output, with styling for the 'Status' column
151
  results_output = gr.DataFrame(
152
  headers=["Requirement", "Reason", "Status"],
 
161
  analyze_btn.click(
162
  fn=analyze_wod,
163
  inputs=[file_input, type_input],
164
+ outputs=[prediction_output, results_output]
165
  )
166
 
167
  # --- Launch the Application with Authentication ---