Spaces:
Running
Running
requirements txt update
Browse files
app.py
CHANGED
|
@@ -7604,34 +7604,56 @@ with gr.Blocks(
|
|
| 7604 |
exist_ok=True
|
| 7605 |
)
|
| 7606 |
|
| 7607 |
-
# Generate
|
| 7608 |
import_statements = extract_import_statements(code)
|
| 7609 |
requirements_content = generate_requirements_txt_with_llm(import_statements)
|
| 7610 |
|
| 7611 |
import tempfile
|
| 7612 |
|
| 7613 |
-
#
|
| 7614 |
-
|
| 7615 |
-
|
| 7616 |
-
|
| 7617 |
-
|
| 7618 |
-
|
| 7619 |
-
|
| 7620 |
-
|
| 7621 |
-
|
| 7622 |
-
|
| 7623 |
-
|
| 7624 |
-
|
| 7625 |
-
|
| 7626 |
-
|
| 7627 |
-
|
| 7628 |
-
|
| 7629 |
-
|
| 7630 |
-
|
| 7631 |
-
|
| 7632 |
-
|
| 7633 |
-
|
| 7634 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7635 |
|
| 7636 |
# Add anycoder tag to existing README
|
| 7637 |
add_anycoder_tag_to_readme(api, repo_id)
|
|
@@ -7980,34 +8002,56 @@ with gr.Blocks(
|
|
| 7980 |
import os
|
| 7981 |
os.unlink(temp_path)
|
| 7982 |
else:
|
| 7983 |
-
# Generate
|
| 7984 |
import_statements = extract_import_statements(code)
|
| 7985 |
requirements_content = generate_requirements_txt_with_llm(import_statements)
|
| 7986 |
|
| 7987 |
import tempfile
|
| 7988 |
|
| 7989 |
-
#
|
| 7990 |
-
|
| 7991 |
-
|
| 7992 |
-
|
| 7993 |
-
|
| 7994 |
-
|
| 7995 |
-
|
| 7996 |
-
|
| 7997 |
-
|
| 7998 |
-
|
| 7999 |
-
|
| 8000 |
-
|
| 8001 |
-
|
| 8002 |
-
|
| 8003 |
-
|
| 8004 |
-
|
| 8005 |
-
|
| 8006 |
-
|
| 8007 |
-
|
| 8008 |
-
|
| 8009 |
-
|
| 8010 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8011 |
|
| 8012 |
# Add anycoder tag to existing README
|
| 8013 |
add_anycoder_tag_to_readme(api, repo_id)
|
|
|
|
| 7604 |
exist_ok=True
|
| 7605 |
)
|
| 7606 |
|
| 7607 |
+
# Generate requirements.txt for Streamlit apps and upload only if needed
|
| 7608 |
import_statements = extract_import_statements(code)
|
| 7609 |
requirements_content = generate_requirements_txt_with_llm(import_statements)
|
| 7610 |
|
| 7611 |
import tempfile
|
| 7612 |
|
| 7613 |
+
# Check if we need to upload requirements.txt
|
| 7614 |
+
should_upload_requirements = True
|
| 7615 |
+
if is_update:
|
| 7616 |
+
try:
|
| 7617 |
+
# Try to get existing requirements.txt content
|
| 7618 |
+
existing_requirements = api.hf_hub_download(
|
| 7619 |
+
repo_id=repo_id,
|
| 7620 |
+
filename="requirements.txt",
|
| 7621 |
+
repo_type="space"
|
| 7622 |
+
)
|
| 7623 |
+
with open(existing_requirements, 'r') as f:
|
| 7624 |
+
existing_content = f.read().strip()
|
| 7625 |
+
|
| 7626 |
+
# Compare with new content
|
| 7627 |
+
if existing_content == requirements_content.strip():
|
| 7628 |
+
should_upload_requirements = False
|
| 7629 |
+
|
| 7630 |
+
except Exception:
|
| 7631 |
+
# File doesn't exist or can't be accessed, so we should upload
|
| 7632 |
+
should_upload_requirements = True
|
| 7633 |
+
|
| 7634 |
+
# Upload requirements.txt only if needed
|
| 7635 |
+
if should_upload_requirements:
|
| 7636 |
+
try:
|
| 7637 |
+
with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False) as f:
|
| 7638 |
+
f.write(requirements_content)
|
| 7639 |
+
requirements_temp_path = f.name
|
| 7640 |
+
|
| 7641 |
+
api.upload_file(
|
| 7642 |
+
path_or_fileobj=requirements_temp_path,
|
| 7643 |
+
path_in_repo="requirements.txt",
|
| 7644 |
+
repo_id=repo_id,
|
| 7645 |
+
repo_type="space"
|
| 7646 |
+
)
|
| 7647 |
+
except Exception as e:
|
| 7648 |
+
error_msg = str(e)
|
| 7649 |
+
if "403 Forbidden" in error_msg and "write token" in error_msg:
|
| 7650 |
+
return gr.update(value=f"Error uploading requirements.txt: Permission denied. Please ensure you have write access to {repo_id} and your token has the correct permissions.", visible=True)
|
| 7651 |
+
else:
|
| 7652 |
+
return gr.update(value=f"Error uploading requirements.txt: {e}", visible=True)
|
| 7653 |
+
finally:
|
| 7654 |
+
import os
|
| 7655 |
+
if 'requirements_temp_path' in locals():
|
| 7656 |
+
os.unlink(requirements_temp_path)
|
| 7657 |
|
| 7658 |
# Add anycoder tag to existing README
|
| 7659 |
add_anycoder_tag_to_readme(api, repo_id)
|
|
|
|
| 8002 |
import os
|
| 8003 |
os.unlink(temp_path)
|
| 8004 |
else:
|
| 8005 |
+
# Generate requirements.txt for Gradio apps and upload only if needed
|
| 8006 |
import_statements = extract_import_statements(code)
|
| 8007 |
requirements_content = generate_requirements_txt_with_llm(import_statements)
|
| 8008 |
|
| 8009 |
import tempfile
|
| 8010 |
|
| 8011 |
+
# Check if we need to upload requirements.txt
|
| 8012 |
+
should_upload_requirements = True
|
| 8013 |
+
if is_update:
|
| 8014 |
+
try:
|
| 8015 |
+
# Try to get existing requirements.txt content
|
| 8016 |
+
existing_requirements = api.hf_hub_download(
|
| 8017 |
+
repo_id=repo_id,
|
| 8018 |
+
filename="requirements.txt",
|
| 8019 |
+
repo_type="space"
|
| 8020 |
+
)
|
| 8021 |
+
with open(existing_requirements, 'r') as f:
|
| 8022 |
+
existing_content = f.read().strip()
|
| 8023 |
+
|
| 8024 |
+
# Compare with new content
|
| 8025 |
+
if existing_content == requirements_content.strip():
|
| 8026 |
+
should_upload_requirements = False
|
| 8027 |
+
|
| 8028 |
+
except Exception:
|
| 8029 |
+
# File doesn't exist or can't be accessed, so we should upload
|
| 8030 |
+
should_upload_requirements = True
|
| 8031 |
+
|
| 8032 |
+
# Upload requirements.txt only if needed
|
| 8033 |
+
if should_upload_requirements:
|
| 8034 |
+
try:
|
| 8035 |
+
with tempfile.NamedTemporaryFile("w", suffix=".txt", delete=False) as f:
|
| 8036 |
+
f.write(requirements_content)
|
| 8037 |
+
requirements_temp_path = f.name
|
| 8038 |
+
|
| 8039 |
+
api.upload_file(
|
| 8040 |
+
path_or_fileobj=requirements_temp_path,
|
| 8041 |
+
path_in_repo="requirements.txt",
|
| 8042 |
+
repo_id=repo_id,
|
| 8043 |
+
repo_type="space"
|
| 8044 |
+
)
|
| 8045 |
+
except Exception as e:
|
| 8046 |
+
error_msg = str(e)
|
| 8047 |
+
if "403 Forbidden" in error_msg and "write token" in error_msg:
|
| 8048 |
+
return gr.update(value=f"Error uploading requirements.txt: Permission denied. Please ensure you have write access to {repo_id} and your token has the correct permissions.", visible=True)
|
| 8049 |
+
else:
|
| 8050 |
+
return gr.update(value=f"Error uploading requirements.txt: {e}", visible=True)
|
| 8051 |
+
finally:
|
| 8052 |
+
import os
|
| 8053 |
+
if 'requirements_temp_path' in locals():
|
| 8054 |
+
os.unlink(requirements_temp_path)
|
| 8055 |
|
| 8056 |
# Add anycoder tag to existing README
|
| 8057 |
add_anycoder_tag_to_readme(api, repo_id)
|