Mxltic commited on
Commit
078695b
Β·
verified Β·
1 Parent(s): 4c12b3e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -42
app.py CHANGED
@@ -5,13 +5,15 @@ import sys
5
  import importlib.util
6
  import gradio as gr
7
 
8
- REPO_DIR = "/app/private_repo"
 
9
  GITHUB_REPO = os.getenv("GITHUB_REPO", "").strip()
10
  GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", "").strip()
11
 
12
  def setup_github_clone():
13
  """Setup GitHub clone with token authentication if available"""
14
  if GITHUB_TOKEN and GITHUB_REPO:
 
15
  if "github.com" in GITHUB_REPO:
16
  auth_url = GITHUB_REPO.replace(
17
  "https://github.com/",
@@ -29,10 +31,12 @@ def load_private_code():
29
  print("❌ GITHUB_REPO environment variable not set")
30
  return False
31
 
 
32
  if os.path.exists(REPO_DIR):
33
  print("🧹 Cleaning up existing repository...")
34
  shutil.rmtree(REPO_DIR)
35
 
 
36
  print(f"πŸ“₯ Cloning repository from: {GITHUB_REPO}")
37
  clone_url = setup_github_clone()
38
 
@@ -47,22 +51,11 @@ def load_private_code():
47
 
48
  if result.returncode != 0:
49
  print(f"❌ Git clone failed: {result.stderr}")
50
- # Try without token if authenticated failed
51
- if GITHUB_TOKEN:
52
- print("πŸ”„ Retrying without token...")
53
- result = subprocess.run(
54
- ["git", "clone", "--depth", "1", GITHUB_REPO, REPO_DIR],
55
- capture_output=True,
56
- text=True,
57
- timeout=300
58
- )
59
- if result.returncode != 0:
60
- return False
61
- else:
62
- return False
63
 
64
  print("βœ… Repository cloned successfully!")
65
 
 
66
  requirements_path = os.path.join(REPO_DIR, "requirements.txt")
67
  if os.path.exists(requirements_path):
68
  print("πŸ“¦ Installing dependencies from requirements.txt...")
@@ -97,46 +90,56 @@ def create_fallback_ui():
97
 
98
  gr.Markdown(
99
  """
100
- # πŸš€ Tiko - TikTok Downloader
 
 
 
 
 
101
 
102
- ## ⚠️ Setup Required
103
 
104
- To use Tiko, you need to configure your private GitHub repository.
 
 
105
 
106
- ### πŸ”§ Environment Variables Required:
107
 
108
- - `GITHUB_REPO`: Your private repository URL
109
- Example: `https://github.com/yourusername/your-private-repo`
110
-
111
- - `GITHUB_TOKEN` (Optional): Personal access token for private repos
112
 
113
- ### πŸ“ Repository Structure Expected:
114
 
115
- ```
116
- your-private-repo/
117
- β”œβ”€β”€ app.py # Main application
118
- β”œβ”€β”€ requirements.txt # Dependencies (optional)
119
- └── ... # Other files
120
- ```
121
 
122
- ### 🎯 In your `app.py`, make sure you have:
123
- ```python
124
- def main_app():
125
- # Your Tiko UI code here
126
- return demo
127
- ```
128
 
129
- **Need help?** Check the documentation or contact support.
 
 
 
 
 
130
  """
131
  )
132
 
133
- with gr.Accordion("πŸ” Debug Information", open=False):
 
 
 
 
 
 
 
 
 
134
  gr.Markdown(f"""
135
- **Current Environment:**
136
  - GITHUB_REPO: `{GITHUB_REPO or 'Not set'}`
137
  - GITHUB_TOKEN: `{'Set' if GITHUB_TOKEN else 'Not set'}`
138
- - Python Path: `{sys.path}`
139
- - Working Directory: `{os.getcwd()}`
140
  """)
141
 
142
  return demo
@@ -151,12 +154,14 @@ def load_private_app():
151
 
152
  print(f"πŸ“‚ Loading app from: {private_app_path}")
153
 
 
154
  spec = importlib.util.spec_from_file_location("tiko_private", private_app_path)
155
  private_module = importlib.util.module_from_spec(spec)
156
  spec.loader.exec_module(private_module)
157
 
158
  print("βœ… Private module imported successfully!")
159
 
 
160
  if hasattr(private_module, "main_app"):
161
  print("🎯 Found main_app() function, launching...")
162
  return private_module.main_app()
@@ -167,16 +172,31 @@ def load_private_app():
167
  print("🎯 Found create_tiko_ui() function, launching...")
168
  return private_module.create_tiko_ui()
169
  else:
170
- raise AttributeError("No valid app function found (expected: main_app, demo, or create_tiko_ui)")
 
 
 
 
 
 
 
 
 
 
 
171
 
172
  except Exception as e:
173
  print(f"❌ Failed to load private app: {str(e)}")
174
  raise
175
 
 
176
  print("=" * 50)
177
  print("πŸš€ Tiko - TikTok Downloader Initializing...")
178
  print("=" * 50)
 
 
179
 
 
180
  if load_private_code():
181
  try:
182
  print("πŸŽ‰ Successfully loaded private code, launching Tiko...")
@@ -192,10 +212,11 @@ else:
192
  print("πŸ”„ Launching setup UI...")
193
  demo = create_fallback_ui()
194
 
 
195
  if __name__ == "__main__":
196
  print("🌐 Starting Gradio server...")
197
  demo.launch(
198
  server_name="0.0.0.0",
199
  server_port=7860,
200
- share=False
201
  )
 
5
  import importlib.util
6
  import gradio as gr
7
 
8
+ # Configuration - USE DIFFERENT PATH
9
+ REPO_DIR = "/tmp/private_repo" # Changed to /tmp which is writable
10
  GITHUB_REPO = os.getenv("GITHUB_REPO", "").strip()
11
  GITHUB_TOKEN = os.getenv("GITHUB_TOKEN", "").strip()
12
 
13
  def setup_github_clone():
14
  """Setup GitHub clone with token authentication if available"""
15
  if GITHUB_TOKEN and GITHUB_REPO:
16
+ # Replace URL with token authentication
17
  if "github.com" in GITHUB_REPO:
18
  auth_url = GITHUB_REPO.replace(
19
  "https://github.com/",
 
31
  print("❌ GITHUB_REPO environment variable not set")
32
  return False
33
 
34
+ # Clean up existing repo
35
  if os.path.exists(REPO_DIR):
36
  print("🧹 Cleaning up existing repository...")
37
  shutil.rmtree(REPO_DIR)
38
 
39
+ # Clone repository
40
  print(f"πŸ“₯ Cloning repository from: {GITHUB_REPO}")
41
  clone_url = setup_github_clone()
42
 
 
51
 
52
  if result.returncode != 0:
53
  print(f"❌ Git clone failed: {result.stderr}")
54
+ return False
 
 
 
 
 
 
 
 
 
 
 
 
55
 
56
  print("βœ… Repository cloned successfully!")
57
 
58
+ # Install requirements
59
  requirements_path = os.path.join(REPO_DIR, "requirements.txt")
60
  if os.path.exists(requirements_path):
61
  print("πŸ“¦ Installing dependencies from requirements.txt...")
 
90
 
91
  gr.Markdown(
92
  """
93
+ <div style="text-align: center;">
94
+ <h1>πŸš€ Tiko - TikTok Downloader</h1>
95
+ <h3>Premium TikTok Content Downloader</h3>
96
+ </div>
97
+
98
+ ## ⚠️ Setup In Progress
99
 
100
+ We're currently setting up your Tiko instance. This might be because:
101
 
102
+ - πŸ”„ First-time setup is running
103
+ - πŸ“₯ Downloading latest updates
104
+ - βš™οΈ Installing dependencies
105
 
106
+ ### 🎯 What's Happening?
107
 
108
+ Tiko is cloning your private repository from GitHub and setting up the environment.
 
 
 
109
 
110
+ **Repository:** `https://github.com/miftahganzz/Tiko`
111
 
112
+ ### ⏳ Next Steps:
 
 
 
 
 
113
 
114
+ 1. Wait a few moments
115
+ 2. Refresh this page
116
+ 3. The app should load automatically
 
 
 
117
 
118
+ If you continue to see this message, check:
119
+ - GitHub repository URL is correct
120
+ - Repository is accessible
121
+ - Enough storage space available
122
+
123
+ **Need help?** Contact support.
124
  """
125
  )
126
 
127
+ # Add refresh button
128
+ refresh_btn = gr.Button("πŸ”„ Refresh Page", size="lg")
129
+ refresh_btn.click(
130
+ fn=lambda: None,
131
+ inputs=[],
132
+ outputs=[]
133
+ )
134
+
135
+ # Debug info
136
+ with gr.Accordion("πŸ” Technical Details", open=False):
137
  gr.Markdown(f"""
138
+ **Environment Info:**
139
  - GITHUB_REPO: `{GITHUB_REPO or 'Not set'}`
140
  - GITHUB_TOKEN: `{'Set' if GITHUB_TOKEN else 'Not set'}`
141
+ - Repo Directory: `{REPO_DIR}`
142
+ - Python Path: `{sys.executable}`
143
  """)
144
 
145
  return demo
 
154
 
155
  print(f"πŸ“‚ Loading app from: {private_app_path}")
156
 
157
+ # Dynamically import the private module
158
  spec = importlib.util.spec_from_file_location("tiko_private", private_app_path)
159
  private_module = importlib.util.module_from_spec(spec)
160
  spec.loader.exec_module(private_module)
161
 
162
  print("βœ… Private module imported successfully!")
163
 
164
+ # Get the main app function
165
  if hasattr(private_module, "main_app"):
166
  print("🎯 Found main_app() function, launching...")
167
  return private_module.main_app()
 
172
  print("🎯 Found create_tiko_ui() function, launching...")
173
  return private_module.create_tiko_ui()
174
  else:
175
+ # Try to find any function that returns a Gradio interface
176
+ for attr_name in dir(private_module):
177
+ attr = getattr(private_module, attr_name)
178
+ if callable(attr) and not attr_name.startswith('_'):
179
+ try:
180
+ result = attr()
181
+ if isinstance(result, (gr.Blocks, gr.Interface)):
182
+ print(f"🎯 Found function {attr_name}, launching...")
183
+ return result
184
+ except:
185
+ continue
186
+ raise AttributeError("No valid Gradio app found")
187
 
188
  except Exception as e:
189
  print(f"❌ Failed to load private app: {str(e)}")
190
  raise
191
 
192
+ # Main execution flow
193
  print("=" * 50)
194
  print("πŸš€ Tiko - TikTok Downloader Initializing...")
195
  print("=" * 50)
196
+ print(f"πŸ“ Repository: {GITHUB_REPO}")
197
+ print(f"πŸ“‚ Target Directory: {REPO_DIR}")
198
 
199
+ # Try to load private code
200
  if load_private_code():
201
  try:
202
  print("πŸŽ‰ Successfully loaded private code, launching Tiko...")
 
212
  print("πŸ”„ Launching setup UI...")
213
  demo = create_fallback_ui()
214
 
215
+ # Launch the application
216
  if __name__ == "__main__":
217
  print("🌐 Starting Gradio server...")
218
  demo.launch(
219
  server_name="0.0.0.0",
220
  server_port=7860,
221
+ share=True
222
  )