alpercagann commited on
Commit
9a88db2
·
1 Parent(s): 1893501

Add PyTorch testing to app

Browse files
Files changed (1) hide show
  1. app.py +23 -16
app.py CHANGED
@@ -1,12 +1,22 @@
1
- # Minimal app.py that doesn't require torch
2
  import os
3
  import sys
4
 
5
- # Print environment information for debugging
6
  print("==== Environment Information ====")
7
  print(f"Python version: {sys.version}")
8
  print(f"Working directory: {os.getcwd()}")
9
- print(f"Directory contents: {os.listdir('.')}")
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  # Simple Gradio interface
12
  import gradio as gr
@@ -14,25 +24,22 @@ import gradio as gr
14
  def hello(name):
15
  if not name:
16
  name = "World"
17
- return f"Hello, {name}!"
 
 
 
 
 
 
18
 
19
- # Create a simple Gradio interface
20
  demo = gr.Interface(
21
  fn=hello,
22
  inputs="text",
23
  outputs="text",
24
- title="SonicDiffusion - Setup Test",
25
- description="This is a test app to verify the environment is working."
26
  )
27
 
28
  if __name__ == "__main__":
29
- # Try to print installed packages
30
- try:
31
- import subprocess
32
- print("==== Installed Packages ====")
33
- subprocess.run([sys.executable, "-m", "pip", "list"])
34
- except Exception as e:
35
- print(f"Error listing packages: {e}")
36
-
37
- # Launch the demo
38
  demo.launch()
 
 
1
  import os
2
  import sys
3
 
4
+ # Print environment information
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__}")
13
+ print(f"CUDA available: {torch.cuda.is_available()}")
14
+ if torch.cuda.is_available():
15
+ print(f"CUDA device: {torch.cuda.get_device_name(0)}")
16
+ torch_available = True
17
+ except ImportError as e:
18
+ print(f"PyTorch import error: {e}")
19
+ torch_available = False
20
 
21
  # Simple Gradio interface
22
  import gradio as gr
 
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()