renhang commited on
Commit
4515b1f
·
1 Parent(s): 8e872fa

Add automatic download of examples data from GitHub repository

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -3,11 +3,53 @@ import gradio as gr
3
  import os
4
  import json
5
  import tempfile
 
 
6
  from pathlib import Path
7
 
8
  from model import Jamify
9
  from utils import json_to_text, text_to_json
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  # Initialize the Jamify model once
12
  print("Initializing Jamify model...")
13
  jamify_model = Jamify()
 
3
  import os
4
  import json
5
  import tempfile
6
+ import requests
7
+ import subprocess
8
  from pathlib import Path
9
 
10
  from model import Jamify
11
  from utils import json_to_text, text_to_json
12
 
13
+ def download_examples_data():
14
+ """Download examples data from GitHub repository if not already present"""
15
+ examples_dir = Path("examples")
16
+
17
+ # Check if examples directory exists and has content
18
+ if examples_dir.exists() and any(examples_dir.iterdir()):
19
+ print("Examples directory already exists with content, skipping download.")
20
+ return
21
+
22
+ print("Downloading examples data from GitHub...")
23
+
24
+ # Create examples directory if it doesn't exist
25
+ examples_dir.mkdir(exist_ok=True)
26
+
27
+ # Clone the examples repository
28
+ repo_url = "https://github.com/xhhhhang/jam-examples.git"
29
+ temp_dir = Path("temp_examples")
30
+
31
+ try:
32
+ # Clone the repository to a temporary location
33
+ subprocess.run(["git", "clone", repo_url, str(temp_dir)], check=True)
34
+
35
+ # Copy all contents to examples directory
36
+ subprocess.run(["cp", "-r", f"{temp_dir}/*", str(examples_dir)], check=True)
37
+
38
+ print("Successfully downloaded examples data.")
39
+
40
+ except subprocess.CalledProcessError as e:
41
+ print(f"Error downloading examples: {e}")
42
+ print("Please ensure the GitHub repository exists and is accessible.")
43
+ except Exception as e:
44
+ print(f"Unexpected error downloading examples: {e}")
45
+ finally:
46
+ # Clean up temporary directory
47
+ if temp_dir.exists():
48
+ subprocess.run(["rm", "-rf", str(temp_dir)])
49
+
50
+ # Download examples data at startup
51
+ download_examples_data()
52
+
53
  # Initialize the Jamify model once
54
  print("Initializing Jamify model...")
55
  jamify_model = Jamify()