hmusman2804045-max commited on
Commit
8a13df3
·
1 Parent(s): 58b3cf9

Configure app for Hugging Face Gradio SDK deployment

Browse files
Files changed (4) hide show
  1. .github/workflows/deploy.yml +9 -13
  2. .gitignore +2 -0
  3. app.py +24 -1
  4. requirements.txt +2 -0
.github/workflows/deploy.yml CHANGED
@@ -1,4 +1,4 @@
1
- name: Deploy to Modal.com
2
 
3
  on:
4
  push:
@@ -7,23 +7,19 @@ on:
7
 
8
  jobs:
9
  deploy:
10
- name: Deploy FastAPI to Modal.com
11
  runs-on: ubuntu-latest
12
 
13
  steps:
14
  - name: Checkout Repository
15
  uses: actions/checkout@v4
16
-
17
- - name: Set up Python
18
- uses: actions/setup-python@v5
19
  with:
20
- python-version: "3.10"
21
-
22
- - name: Install Modal CLI
23
- run: pip install modal
24
 
25
- - name: Deploy to Modal
26
  env:
27
- MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
28
- MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
29
- run: modal deploy modal_app.py
 
 
 
1
+ name: Deploy to Hugging Face Spaces
2
 
3
  on:
4
  push:
 
7
 
8
  jobs:
9
  deploy:
10
+ name: Sync to Hugging Face Space
11
  runs-on: ubuntu-latest
12
 
13
  steps:
14
  - name: Checkout Repository
15
  uses: actions/checkout@v4
 
 
 
16
  with:
17
+ fetch-depth: 0
 
 
 
18
 
19
+ - name: Push to Hugging Face Space
20
  env:
21
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
22
+ HF_USERNAME: ${{ secrets.HF_USERNAME }}
23
+ run: |
24
+ git push https://$HF_USERNAME:$HF_TOKEN@huggingface.co/spaces/$HF_USERNAME/urdu-sentiment-engine main
25
+
.gitignore CHANGED
@@ -12,4 +12,6 @@ venv/
12
  remove_comments_script.py
13
  *.tsv
14
  *.zip
 
15
  .claude/
 
 
12
  remove_comments_script.py
13
  *.tsv
14
  *.zip
15
+ *.mp4
16
  .claude/
17
+
app.py CHANGED
@@ -168,4 +168,27 @@ def health_check():
168
  if __name__ == "__main__":
169
  import uvicorn
170
  print("Starting FastAPI Uvicorn Server...")
171
- uvicorn.run("app:app", host="0.0.0.0", port=5000, reload=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  if __name__ == "__main__":
169
  import uvicorn
170
  print("Starting FastAPI Uvicorn Server...")
171
+ uvicorn.run("app:app", host="0.0.0.0", port=7860, reload=True)
172
+ else:
173
+ import gradio as gr
174
+
175
+ def gradio_predict(text):
176
+ if not text or not text.strip():
177
+ return {"error": "Please enter valid text."}
178
+ lang = detect_language(text)
179
+ res = engine.predict(text)
180
+ res["language"] = lang
181
+ update_analytics(res, lang)
182
+ return res
183
+
184
+ with gr.Blocks(title="Urdu Sentiment & Emotion Engine") as demo:
185
+ gr.Markdown("# 🇵🇰 Urdu Sentiment & Emotion Analysis Engine")
186
+ gr.Markdown("Multilingual Sentiment and Emotion Analysis for Urdu Script, Roman Urdu, and English/Mixed text.")
187
+ with gr.Row():
188
+ input_text = gr.Textbox(lines=3, placeholder="یہ پروڈکٹ بہت عمدہ ہے / Main aj bohat khush hoon", label="Input Text")
189
+ btn = gr.Button("Analyze Sentiment & Emotion", variant="primary")
190
+ output_json = gr.JSON(label="Analysis Output")
191
+ btn.click(fn=gradio_predict, inputs=input_text, outputs=output_json)
192
+
193
+ app = gr.mount_gradio_app(app, demo, path="/gradio")
194
+
requirements.txt CHANGED
@@ -8,4 +8,6 @@ numpy==1.26.0
8
  pandas==2.2.0
9
  scikit-learn==1.4.0
10
  accelerate==0.29.0
 
 
11
 
 
8
  pandas==2.2.0
9
  scikit-learn==1.4.0
10
  accelerate==0.29.0
11
+ gradio
12
+
13