Update app.py
Browse files
app.py
CHANGED
|
@@ -5,13 +5,15 @@ import sys
|
|
| 5 |
import importlib.util
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
|
|
|
|
| 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 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
| 105 |
|
| 106 |
-
###
|
| 107 |
|
| 108 |
-
|
| 109 |
-
Example: `https://github.com/yourusername/your-private-repo`
|
| 110 |
-
|
| 111 |
-
- `GITHUB_TOKEN` (Optional): Personal access token for private repos
|
| 112 |
|
| 113 |
-
|
| 114 |
|
| 115 |
-
|
| 116 |
-
your-private-repo/
|
| 117 |
-
βββ app.py # Main application
|
| 118 |
-
βββ requirements.txt # Dependencies (optional)
|
| 119 |
-
βββ ... # Other files
|
| 120 |
-
```
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
# Your Tiko UI code here
|
| 126 |
-
return demo
|
| 127 |
-
```
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
"""
|
| 131 |
)
|
| 132 |
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
gr.Markdown(f"""
|
| 135 |
-
**
|
| 136 |
- GITHUB_REPO: `{GITHUB_REPO or 'Not set'}`
|
| 137 |
- GITHUB_TOKEN: `{'Set' if GITHUB_TOKEN else 'Not set'}`
|
| 138 |
-
-
|
| 139 |
-
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 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 |
)
|