streamlit load issue
Browse files
app.py
CHANGED
@@ -1715,25 +1715,53 @@ def fetch_hf_space_content(username: str, project_name: str) -> str:
|
|
1715 |
sdk = space_info.sdk
|
1716 |
main_file = None
|
1717 |
|
|
|
1718 |
if sdk == "static":
|
1719 |
-
|
1720 |
elif sdk == "gradio":
|
1721 |
-
|
1722 |
elif sdk == "streamlit":
|
1723 |
-
|
1724 |
else:
|
1725 |
-
# Try common files
|
1726 |
-
|
1727 |
-
|
1728 |
-
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
1732 |
-
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1737 |
|
1738 |
if main_file:
|
1739 |
content = api.hf_hub_download(
|
@@ -1755,7 +1783,14 @@ Main File: {main_file}
|
|
1755 |
|
1756 |
{file_content}"""
|
1757 |
else:
|
1758 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1759 |
|
1760 |
except Exception as e:
|
1761 |
return f"Error fetching space content: {str(e)}"
|
|
|
1715 |
sdk = space_info.sdk
|
1716 |
main_file = None
|
1717 |
|
1718 |
+
# Define file patterns to try based on SDK
|
1719 |
if sdk == "static":
|
1720 |
+
file_patterns = ["index.html"]
|
1721 |
elif sdk == "gradio":
|
1722 |
+
file_patterns = ["app.py", "main.py", "gradio_app.py"]
|
1723 |
elif sdk == "streamlit":
|
1724 |
+
file_patterns = ["streamlit_app.py", "src/streamlit_app.py", "app.py", "src/app.py", "main.py", "src/main.py", "Home.py", "src/Home.py", "🏠_Home.py", "src/🏠_Home.py", "1_🏠_Home.py", "src/1_🏠_Home.py"]
|
1725 |
else:
|
1726 |
+
# Try common files for unknown SDKs
|
1727 |
+
file_patterns = ["app.py", "src/app.py", "index.html", "streamlit_app.py", "src/streamlit_app.py", "main.py", "src/main.py", "Home.py", "src/Home.py"]
|
1728 |
+
|
1729 |
+
# Try to find and download the main file
|
1730 |
+
for file in file_patterns:
|
1731 |
+
try:
|
1732 |
+
content = api.hf_hub_download(
|
1733 |
+
repo_id=f"{username}/{project_name}",
|
1734 |
+
filename=file,
|
1735 |
+
repo_type="space"
|
1736 |
+
)
|
1737 |
+
main_file = file
|
1738 |
+
break
|
1739 |
+
except:
|
1740 |
+
continue
|
1741 |
+
|
1742 |
+
# If still no main file found, try to list repository files and find Python files
|
1743 |
+
if not main_file and sdk in ["streamlit", "gradio"]:
|
1744 |
+
try:
|
1745 |
+
from huggingface_hub import list_repo_files
|
1746 |
+
files = list_repo_files(repo_id=f"{username}/{project_name}", repo_type="space")
|
1747 |
+
|
1748 |
+
# Look for Python files that might be the main file (root and src/ directory)
|
1749 |
+
python_files = [f for f in files if f.endswith('.py') and not f.startswith('.') and
|
1750 |
+
(('/' not in f) or f.startswith('src/'))]
|
1751 |
+
|
1752 |
+
for py_file in python_files:
|
1753 |
+
try:
|
1754 |
+
content = api.hf_hub_download(
|
1755 |
+
repo_id=f"{username}/{project_name}",
|
1756 |
+
filename=py_file,
|
1757 |
+
repo_type="space"
|
1758 |
+
)
|
1759 |
+
main_file = py_file
|
1760 |
+
break
|
1761 |
+
except:
|
1762 |
+
continue
|
1763 |
+
except:
|
1764 |
+
pass
|
1765 |
|
1766 |
if main_file:
|
1767 |
content = api.hf_hub_download(
|
|
|
1783 |
|
1784 |
{file_content}"""
|
1785 |
else:
|
1786 |
+
# Try to get more information about available files for debugging
|
1787 |
+
try:
|
1788 |
+
from huggingface_hub import list_repo_files
|
1789 |
+
files = list_repo_files(repo_id=f"{username}/{project_name}", repo_type="space")
|
1790 |
+
available_files = [f for f in files if not f.startswith('.') and not f.endswith('.md')]
|
1791 |
+
return f"Error: Could not find main file in space {username}/{project_name}.\n\nSDK: {sdk}\nAvailable files: {', '.join(available_files[:10])}{'...' if len(available_files) > 10 else ''}\n\nTried looking for: {', '.join(file_patterns)}"
|
1792 |
+
except:
|
1793 |
+
return f"Error: Could not find main file in space {username}/{project_name}. Expected files for {sdk} SDK: {', '.join(file_patterns) if 'file_patterns' in locals() else 'standard files'}"
|
1794 |
|
1795 |
except Exception as e:
|
1796 |
return f"Error fetching space content: {str(e)}"
|