alpercagann commited on
Commit
34f8aaa
·
1 Parent(s): 1cac1fa

Add download testing to app

Browse files
Files changed (1) hide show
  1. app.py +36 -11
app.py CHANGED
@@ -5,8 +5,9 @@ import sys
5
  print("==== Environment Information ====")
6
  print(f"Python version: {sys.version}")
7
  print(f"Working directory: {os.getcwd()}")
 
8
 
9
- # Try importing torch
10
  try:
11
  import torch
12
  print(f"PyTorch version: {torch.__version__}")
@@ -21,25 +22,49 @@ except ImportError as e:
21
  # Simple Gradio interface
22
  import gradio as gr
23
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def hello(name):
25
  if not name:
26
  name = "World"
27
 
 
 
28
  if torch_available:
29
  # Create a simple tensor to test PyTorch
30
  tensor = torch.rand(3, 3)
31
- return f"Hello, {name}! PyTorch is working. Here's a random tensor:\n{tensor}"
32
  else:
33
- return f"Hello, {name}! PyTorch is NOT available."
 
 
34
 
35
- # Create the interface
36
- demo = gr.Interface(
37
- fn=hello,
38
- inputs="text",
39
- outputs="text",
40
- title="SonicDiffusion - PyTorch Test",
41
- description="Testing if PyTorch is working properly in the environment."
42
- )
 
 
 
 
 
 
 
 
43
 
44
  if __name__ == "__main__":
45
  demo.launch()
 
5
  print("==== Environment Information ====")
6
  print(f"Python version: {sys.version}")
7
  print(f"Working directory: {os.getcwd()}")
8
+ print(f"Directory contents: {os.listdir('.')}")
9
 
10
+ # Import required packages
11
  try:
12
  import torch
13
  print(f"PyTorch version: {torch.__version__}")
 
22
  # Simple Gradio interface
23
  import gradio as gr
24
 
25
+ def test_download():
26
+ """Test the download functionality"""
27
+ try:
28
+ from download_assets import download_test_file
29
+ success = download_test_file()
30
+ if success:
31
+ return "Download test successful! Check the assets folder."
32
+ else:
33
+ return "Download test failed. See logs for details."
34
+ except Exception as e:
35
+ return f"Error while testing download: {str(e)}"
36
+
37
  def hello(name):
38
  if not name:
39
  name = "World"
40
 
41
+ result = f"Hello, {name}!\n\n"
42
+
43
  if torch_available:
44
  # Create a simple tensor to test PyTorch
45
  tensor = torch.rand(3, 3)
46
+ result += f"PyTorch is working. Random tensor:\n{tensor}\n\n"
47
  else:
48
+ result += "PyTorch is NOT available.\n\n"
49
+
50
+ return result
51
 
52
+ # Create the Gradio interface with tabs
53
+ with gr.Blocks(title="SonicDiffusion - Setup Tests") as demo:
54
+ gr.Markdown("# SonicDiffusion - Environment Tests")
55
+
56
+ with gr.Tab("Hello Test"):
57
+ gr.Markdown("Test basic functionality and PyTorch")
58
+ name_input = gr.Textbox(label="Enter your name")
59
+ hello_btn = gr.Button("Say Hello")
60
+ hello_output = gr.Textbox(label="Output")
61
+ hello_btn.click(fn=hello, inputs=name_input, outputs=hello_output)
62
+
63
+ with gr.Tab("Download Test"):
64
+ gr.Markdown("Test downloading files from Google Drive")
65
+ download_btn = gr.Button("Test Download")
66
+ download_output = gr.Textbox(label="Download Result")
67
+ download_btn.click(fn=test_download, inputs=None, outputs=download_output)
68
 
69
  if __name__ == "__main__":
70
  demo.launch()