Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -448,8 +448,16 @@ def process_code_file(file_obj):
|
|
448 |
return None, "No file uploaded", {}
|
449 |
|
450 |
try:
|
451 |
-
|
452 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
453 |
language = detect_language(file_extension)
|
454 |
|
455 |
# Calculate metrics
|
@@ -469,7 +477,7 @@ def process_code_file(file_obj):
|
|
469 |
except Exception as e:
|
470 |
print(f"Warning: Failed to create vectorstore: {e}")
|
471 |
|
472 |
-
return session_id, f"✅ Successfully analyzed {
|
473 |
except Exception as e:
|
474 |
return None, f"Error processing file: {str(e)}", {}
|
475 |
|
@@ -582,7 +590,7 @@ with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
|
582 |
|
583 |
# Update event handlers
|
584 |
upload_button.click(
|
585 |
-
process_code_file,
|
586 |
inputs=[file_input],
|
587 |
outputs=[current_session_id, file_status, code_state]
|
588 |
).then(
|
|
|
448 |
return None, "No file uploaded", {}
|
449 |
|
450 |
try:
|
451 |
+
# Handle both file objects and bytes objects
|
452 |
+
if isinstance(file_obj, bytes):
|
453 |
+
content = file_obj.decode('utf-8')
|
454 |
+
file_name = "uploaded_file"
|
455 |
+
file_extension = ".txt" # Default extension
|
456 |
+
else:
|
457 |
+
content = file_obj.read().decode('utf-8')
|
458 |
+
file_name = getattr(file_obj, 'name', 'uploaded_file')
|
459 |
+
file_extension = Path(file_name).suffix.lower()
|
460 |
+
|
461 |
language = detect_language(file_extension)
|
462 |
|
463 |
# Calculate metrics
|
|
|
477 |
except Exception as e:
|
478 |
print(f"Warning: Failed to create vectorstore: {e}")
|
479 |
|
480 |
+
return session_id, f"✅ Successfully analyzed {file_name}", metrics
|
481 |
except Exception as e:
|
482 |
return None, f"Error processing file: {str(e)}", {}
|
483 |
|
|
|
590 |
|
591 |
# Update event handlers
|
592 |
upload_button.click(
|
593 |
+
lambda x: process_code_file(x),
|
594 |
inputs=[file_input],
|
595 |
outputs=[current_session_id, file_status, code_state]
|
596 |
).then(
|