Alphin Jain commited on
Commit
eab46f4
·
1 Parent(s): 0a7d2c2

Initial commit: Math Problem Solver application

Browse files
.github/workflows/deploy-to-huggingface.yml ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Deploy to Hugging Face
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ pull_request:
7
+ branches: [ main ]
8
+ workflow_dispatch: # Allows manual triggering
9
+
10
+ jobs:
11
+ deploy:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+ with:
16
+ fetch-depth: 0
17
+
18
+ - name: Set up Python
19
+ uses: actions/setup-python@v4
20
+ with:
21
+ python-version: '3.10'
22
+
23
+ - name: Install dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ pip install -r requirements.txt
27
+ pip install git+https://github.com/huggingface/huggingface_hub
28
+
29
+ - name: Configure Hugging Face CLI
30
+ env:
31
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
32
+ run: |
33
+ # Configure Hugging Face CLI
34
+ python -c "from huggingface_hub.hf_api import HfApi; HfApi().set_access_token('$HF_TOKEN')"
35
+
36
+ - name: Deploy to Hugging Face Space
37
+ env:
38
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
39
+ HF_USERNAME: ${{ secrets.HF_USERNAME }}
40
+ SPACE_NAME: "math-problem-solver"
41
+ run: |
42
+ # Clone the repository if it exists, or create a new one
43
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
44
+ git config --global user.name "GitHub Actions"
45
+
46
+ # Try to clone the space or create a new one
47
+ if ! git clone https://huggingface.co/${HF_USERNAME}/${SPACE_NAME}; then
48
+ mkdir -p ${SPACE_NAME}
49
+ cd ${SPACE_NAME}
50
+ git init
51
+ git remote add origin https://huggingface.co/${HF_USERNAME}/${SPACE_NAME}
52
+ echo -e "---\ntitle: Math Problem Solver\nsdk: streamlit\nsdk_version: 1.28.0\nemoji: 🧮\ncolorFrom: blue\ncolorTo: green\npinned: true\n---\n\n# Math Problem Solver\n\nAI-powered math problem solver using Google Gemma 2 and other models." > README.md
53
+ git add README.md
54
+ git commit -m "Initial commit"
55
+ git push --set-upstream https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/${HF_USERNAME}/${SPACE_NAME} main
56
+ cd ..
57
+ fi
58
+
59
+ # Copy all project files to the space directory
60
+ cd ${SPACE_NAME}
61
+ cp -r ../app.py ../requirements.txt . 2>/dev/null || :
62
+ if [ -d "../screenshots" ]; then
63
+ mkdir -p screenshots
64
+ cp -r ../screenshots/* screenshots/ 2>/dev/null || :
65
+ fi
66
+
67
+ # Create or update .gitignore to ignore unnecessary files
68
+ echo ".env" > .gitignore
69
+ echo "__pycache__/" >> .gitignore
70
+ echo ".streamlit/secrets.toml" >> .gitignore
71
+
72
+ # Create Hugging Face Space specific files
73
+ cat > README.md <<EOL
74
+ ---
75
+ title: Math Problem Solver
76
+ sdk: streamlit
77
+ sdk_version: 1.28.0
78
+ emoji: 🧮
79
+ colorFrom: blue
80
+ colorTo: green
81
+ pinned: true
82
+ app_file: app.py
83
+ ---
84
+
85
+ # Math Problem Solver
86
+
87
+ AI-powered math problem solver using Google Gemma 2 and other models through Groq API.
88
+
89
+ ## Features
90
+
91
+ - Solves a wide range of math problems
92
+ - Step-by-step explanations
93
+ - Multiple AI model support
94
+ - Interactive chat interface
95
+
96
+ [GitHub Repository](https://github.com/${{ github.repository }})
97
+ EOL
98
+
99
+ # Commit and push changes
100
+ git add .
101
+ git commit -m "Update from GitHub Actions" || echo "No changes to commit"
102
+ git push https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/${HF_USERNAME}/${SPACE_NAME} main