ratneshpasi03 commited on
Commit
fc1afe5
Β·
verified Β·
1 Parent(s): df2b063

saving changes to hugging face (#2)

Browse files

- final update to save Q&A at hugging face (ad08399d13ad9a895fa668dd27826000f6885c95)

.devcontainer/devcontainer.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "name": "Python 3",
3
- // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
4
- "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
5
- "customizations": {
6
- "codespaces": {
7
- "openFiles": [
8
- "README.md",
9
- "app.py"
10
- ]
11
- },
12
- "vscode": {
13
- "settings": {},
14
- "extensions": [
15
- "ms-python.python",
16
- "ms-python.vscode-pylance"
17
- ]
18
- }
19
- },
20
- "updateContentCommand": "[ -f packages.txt ] && sudo apt update && sudo apt upgrade -y && sudo xargs apt install -y <packages.txt; [ -f requirements.txt ] && pip3 install --user -r requirements.txt; pip3 install --user streamlit; echo 'βœ… Packages installed and Requirements met'",
21
- "postAttachCommand": {
22
- "server": "streamlit run app.py --server.enableCORS false --server.enableXsrfProtection false"
23
- },
24
- "portsAttributes": {
25
- "8501": {
26
- "label": "Application",
27
- "onAutoForward": "openPreview"
28
- }
29
- },
30
- "forwardPorts": [
31
- 8501
32
- ]
33
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
.gitignore CHANGED
@@ -4,4 +4,4 @@ __pycache__/
4
  *.pyo
5
 
6
  # Ignore CSV's present in raw_data folder
7
- */raw_data
 
4
  *.pyo
5
 
6
  # Ignore CSV's present in raw_data folder
7
+ *.env
pages/3_Add_Questions.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import json
3
  from pathlib import Path
4
  from utils.code_services import format_code, execute_code
 
5
 
6
  QUESTIONS_DIR = Path("data/questions")
7
  QUESTIONS_DIR.mkdir(parents=True, exist_ok=True)
@@ -53,6 +54,7 @@ if st.button("Save Question"):
53
  json.dump(metadata, f, indent=4)
54
 
55
  st.success(f"βœ… Question saved successfully! (ID: {question_id})")
 
56
  st.info("refresh in-order to see the applied changes")
57
  if st.button("refresh") :
58
  st.rerun()
 
2
  import json
3
  from pathlib import Path
4
  from utils.code_services import format_code, execute_code
5
+ from utils.save_to_hf import commit_and_push_changes
6
 
7
  QUESTIONS_DIR = Path("data/questions")
8
  QUESTIONS_DIR.mkdir(parents=True, exist_ok=True)
 
54
  json.dump(metadata, f, indent=4)
55
 
56
  st.success(f"βœ… Question saved successfully! (ID: {question_id})")
57
+ commit_and_push_changes()
58
  st.info("refresh in-order to see the applied changes")
59
  if st.button("refresh") :
60
  st.rerun()
pages/4_Edit_Questions.py CHANGED
@@ -3,6 +3,7 @@ import streamlit as st
3
  from pathlib import Path
4
  from utils.load_jsonl import load_data
5
  from utils.code_services import format_code, execute_code
 
6
 
7
  DATA_DIR = Path("data/questions")
8
  JSONL_FILE = "output.jsonl"
@@ -68,6 +69,7 @@ if selected_question:
68
  json.dump(updated_metadata, f, indent=4)
69
 
70
  st.success(f"βœ… Question ID {selected_question_id} updated successfully!")
 
71
  st.info("Refresh to see the applied changes")
72
  if st.button("Refresh"):
73
  st.rerun()
 
3
  from pathlib import Path
4
  from utils.load_jsonl import load_data
5
  from utils.code_services import format_code, execute_code
6
+ from utils.save_to_hf import commit_and_push_changes
7
 
8
  DATA_DIR = Path("data/questions")
9
  JSONL_FILE = "output.jsonl"
 
69
  json.dump(updated_metadata, f, indent=4)
70
 
71
  st.success(f"βœ… Question ID {selected_question_id} updated successfully!")
72
+ commit_and_push_changes()
73
  st.info("Refresh to see the applied changes")
74
  if st.button("Refresh"):
75
  st.rerun()
pages/5_Delete_Question.py CHANGED
@@ -3,6 +3,7 @@ import os
3
  import shutil
4
  from pathlib import Path
5
  from utils.load_jsonl import load_data
 
6
 
7
  DATA_DIR = Path("data/questions")
8
  JSONL_FILE = "output.jsonl"
@@ -62,8 +63,9 @@ if selected_question:
62
  question_folder = DATA_DIR / str(selected_question_id)
63
  if question_folder.exists():
64
  shutil.rmtree(question_folder)
65
- rename_folders(selected_question_id)
66
  st.success(f"βœ… Question ID {selected_question_id} deleted successfully!")
 
67
  st.info("Refresh to see the applied changes")
68
  if st.button("Refresh"):
69
  st.rerun()
 
3
  import shutil
4
  from pathlib import Path
5
  from utils.load_jsonl import load_data
6
+ from utils.save_to_hf import commit_and_push_changes
7
 
8
  DATA_DIR = Path("data/questions")
9
  JSONL_FILE = "output.jsonl"
 
63
  question_folder = DATA_DIR / str(selected_question_id)
64
  if question_folder.exists():
65
  shutil.rmtree(question_folder)
66
+ rename_folders(selected_question_id)
67
  st.success(f"βœ… Question ID {selected_question_id} deleted successfully!")
68
+ commit_and_push_changes()
69
  st.info("Refresh to see the applied changes")
70
  if st.button("Refresh"):
71
  st.rerun()
utils/save_to_hf.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def commit_and_push_changes():
2
+ import os
3
+ import subprocess
4
+ from pathlib import Path
5
+
6
+ # Define the paths
7
+ REPO_DIR = Path(".") # Root directory of your Hugging Face Space repo
8
+ DATA_DIR = REPO_DIR / "data/questions" # Persistent storage in the repo
9
+ JSONL_FILE = REPO_DIR / "output.jsonl"
10
+
11
+ DATA_DIR.mkdir(parents=True, exist_ok=True) # Ensure directory exists
12
+
13
+ GIT_USER = os.getenv("GIT_USER")
14
+ GIT_TOKEN = os.getenv("GIT_TOKEN")
15
+ REPO_URL = f"https://{GIT_USER}:{GIT_TOKEN}@huggingface.co/spaces/VayuBuddy-Question-and-Answer"
16
+
17
+ # Set remote URL before pushing
18
+ subprocess.run(["git", "remote", "set-url", "origin", REPO_URL], check=True)
19
+
20
+ """Automates Git add, commit, and push for updated data."""
21
+ try:
22
+ # Run Git commands
23
+ subprocess.run(["git", "add", "--all"], check=True)
24
+ subprocess.run(["git", "commit", "-m", "Update questions data"], check=True)
25
+ subprocess.run(["git", "push"], check=True)
26
+
27
+ print("βœ… Data committed and pushed successfully!")
28
+
29
+ except subprocess.CalledProcessError as e:
30
+ print(f"❌ Git operation failed: {e}")