spaceB / app.py
ckc99u's picture
Update app.py
39d160c verified
"""
Minimal Gradio Test - Just read and display OBJ file
"""
import gradio as gr
def test_file_upload(input_file):
"""Simple function to test if file upload works"""
print("\n" + "="*60)
print("πŸ” TEST FUNCTION CALLED!")
print(f"Type: {type(input_file)}")
print(f"Value: {input_file}")
print("="*60 + "\n")
if input_file is None:
return "❌ No file uploaded"
try:
# With type="filepath", input_file is a string path
file_path = input_file
print(f"File path: {file_path}")
# Read first 10 lines
with open(file_path, 'r') as f:
lines = [f.readline() for _ in range(10)]
result = "βœ… File uploaded successfully!\n\n"
result += f"File path: {file_path}\n\n"
result += "First 10 lines:\n"
result += "="*50 + "\n"
result += "".join(lines)
result += "="*50
print("SUCCESS! Returning result")
return result
except Exception as e:
error_msg = f"❌ Error: {str(e)}"
print(error_msg)
return error_msg
# Create simple interface
demo = gr.Interface(
fn=test_file_upload,
inputs=gr.File(label="Upload OBJ File", file_types=[".obj"], type="filepath"), # Changed here
outputs=gr.Textbox(label="Result", lines=15),
title="πŸ§ͺ File Upload Test",
description="Upload an OBJ file to test if Gradio file upload is working."
)
if __name__ == "__main__":
print("="*60)
print("Starting minimal Gradio test...")
print("="*60)
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=False,
show_error=True
)