SCGR commited on
Commit
ad1a614
·
1 Parent(s): ad5f9c7

contribute parsing logic

Browse files
frontend/src/pages/MapDetailsPage/MapDetailPage.tsx CHANGED
@@ -463,8 +463,13 @@ export default function MapDetailPage() {
463
  throw new Error(errorData.error || 'Failed to generate caption');
464
  }
465
 
466
- const url = `/upload?imageUrl=${encodeURIComponent(json.image_url)}&isContribution=true&step=2a&imageId=${newId}&imageType=${map.image_type}`;
467
- navigate(url);
 
 
 
 
 
468
 
469
  } catch (error: unknown) {
470
  console.error('Contribution failed:', error);
@@ -966,53 +971,31 @@ export default function MapDetailPage() {
966
  </Container>
967
 
968
  {/* Combined Analysis Structure */}
969
- {filteredMap.raw_json ? (
970
- <>
971
- {/* Try to extract three parts from edited field first (new format) */}
972
- {filteredMap.edited && filteredMap.edited.includes('Description:') ? (
973
- <Container
974
- heading="AI Generated Content"
975
- headingLevel={3}
976
- withHeaderBorder
977
- withInternalPadding
978
- spacing="comfortable"
979
- >
980
- <div className={styles.captionContainer}>
981
- <div className={styles.captionText}>
982
- {filteredMap.edited.split('\n').map((line, index) => (
983
- <div key={index}>
984
- {line.startsWith('Description:') || line.startsWith('Analysis:') || line.startsWith('Recommended Actions:') ? (
985
- <h4 className="font-semibold text-gray-800 mt-4 mb-2">{line}</h4>
986
- ) : line.trim() === '' ? (
987
- <br />
988
- ) : (
989
- <p className="mb-2">{line}</p>
990
- )}
991
- </div>
992
- ))}
993
  </div>
994
- </div>
995
- </Container>
996
- ) : (
997
- <Container
998
- heading="Description"
999
- headingLevel={3}
1000
- withHeaderBorder
1001
- withInternalPadding
1002
- spacing="comfortable"
1003
- >
1004
- <div className={styles.captionContainer}>
1005
- {filteredMap.generated ? (
1006
- <div className={styles.captionText}>
1007
- <p>{filteredMap.edited || filteredMap.generated}</p>
1008
- </div>
1009
- ) : (
1010
- <p>— no caption yet —</p>
1011
- )}
1012
- </div>
1013
- </Container>
1014
- )}
1015
- </>
1016
  ) : (
1017
  <Container
1018
  heading="Description"
 
463
  throw new Error(errorData.error || 'Failed to generate caption');
464
  }
465
 
466
+ // Wait for the VLM response to be processed
467
+ const captionData = await capRes.json();
468
+ console.log('Caption generation response:', captionData);
469
+
470
+ // Now navigate to the upload page with the processed data
471
+ const url = `/upload?imageUrl=${encodeURIComponent(json.image_url)}&isContribution=true&step=2a&imageId=${newId}&imageType=${map.image_type}`;
472
+ navigate(url);
473
 
474
  } catch (error: unknown) {
475
  console.error('Contribution failed:', error);
 
971
  </Container>
972
 
973
  {/* Combined Analysis Structure */}
974
+ {(filteredMap.edited && filteredMap.edited.includes('Description:')) ||
975
+ (filteredMap.generated && filteredMap.generated.includes('Description:')) ? (
976
+ <Container
977
+ heading="AI Generated Content"
978
+ headingLevel={3}
979
+ withHeaderBorder
980
+ withInternalPadding
981
+ spacing="comfortable"
982
+ >
983
+ <div className={styles.captionContainer}>
984
+ <div className={styles.captionText}>
985
+ {(filteredMap.edited || filteredMap.generated || '').split('\n').map((line, index) => (
986
+ <div key={index}>
987
+ {line.startsWith('Description:') || line.startsWith('Analysis:') || line.startsWith('Recommended Actions:') ? (
988
+ <h4 className="font-semibold text-gray-800 mt-4 mb-2">{line}</h4>
989
+ ) : line.trim() === '' ? (
990
+ <br />
991
+ ) : (
992
+ <p className="mb-2">{line}</p>
993
+ )}
 
 
 
 
994
  </div>
995
+ ))}
996
+ </div>
997
+ </div>
998
+ </Container>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
999
  ) : (
1000
  <Container
1001
  heading="Description"
frontend/src/pages/UploadPage/UploadPage.tsx CHANGED
@@ -201,16 +201,22 @@ export default function UploadPage() {
201
  }
202
 
203
  if (data.generated) {
204
- try {
205
- const parsedGenerated = JSON.parse(data.generated);
206
- if (parsedGenerated.analysis) {
207
- setDraft(parsedGenerated.analysis);
208
- } else {
209
- setDraft(data.generated);
 
 
 
 
 
210
  }
211
- } catch (e) {
212
- setDraft(data.generated);
213
  }
 
 
 
214
  }
215
 
216
  let extractedMetadata = data.raw_json?.extracted_metadata;
 
201
  }
202
 
203
  if (data.generated) {
204
+ // Extract the three parts from raw_json.extracted_metadata (same as regular upload flow)
205
+ const extractedMetadataForParts = data.raw_json?.extracted_metadata;
206
+ if (extractedMetadataForParts) {
207
+ if (extractedMetadataForParts.description) {
208
+ setDescription(extractedMetadataForParts.description);
209
+ }
210
+ if (extractedMetadataForParts.analysis) {
211
+ setAnalysis(extractedMetadataForParts.analysis);
212
+ }
213
+ if (extractedMetadataForParts.recommended_actions) {
214
+ setRecommendedActions(extractedMetadataForParts.recommended_actions);
215
  }
 
 
216
  }
217
+
218
+ // Set draft with the generated content for backward compatibility
219
+ setDraft(data.generated);
220
  }
221
 
222
  let extractedMetadata = data.raw_json?.extracted_metadata;