Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- app.py +7 -11
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -6,21 +6,20 @@ from gtts import gTTS
|
|
| 6 |
import re
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
# Branding
|
| 10 |
TITLE = "🇧🇩 Polymath-Bengali-Tutor"
|
| 11 |
DESC = "A Neuro-Symbolic AI Tutor for Rural Education in Bangladesh"
|
| 12 |
|
| 13 |
-
# Load Model (
|
|
|
|
| 14 |
try:
|
| 15 |
-
model_id = "Noushad999/Polymath-1.5B-Bengali-Reasoner" # Tries to load YOUR new model
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 17 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 18 |
except:
|
| 19 |
-
model_id = "Qwen/Qwen2.5-1.5B-Instruct"
|
| 20 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 21 |
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
| 22 |
|
| 23 |
-
#
|
| 24 |
def safe_calculator(text):
|
| 25 |
bangla_digits = "০১২৩৪৫৬৭৮৯"
|
| 26 |
english_digits = "0123456789"
|
|
@@ -40,7 +39,6 @@ def safe_calculator(text):
|
|
| 40 |
|
| 41 |
return None, None, []
|
| 42 |
|
| 43 |
-
# --- RESPONSE GENERATOR ---
|
| 44 |
def ai_tutor(user_input):
|
| 45 |
val, op, nums = safe_calculator(user_input)
|
| 46 |
|
|
@@ -63,18 +61,16 @@ def ai_tutor(user_input):
|
|
| 63 |
except:
|
| 64 |
return ans, None
|
| 65 |
|
| 66 |
-
#
|
| 67 |
-
with gr.Blocks(
|
| 68 |
gr.Markdown(f"# {TITLE}")
|
| 69 |
gr.Markdown(f"### {DESC}")
|
| 70 |
-
|
| 71 |
with gr.Row():
|
| 72 |
-
inp = gr.Textbox(label="
|
| 73 |
btn = gr.Button("Ask Polymath 🧠", variant="primary")
|
| 74 |
with gr.Row():
|
| 75 |
out_txt = gr.Textbox(label="Answer")
|
| 76 |
out_aud = gr.Audio(label="Voice", autoplay=True)
|
| 77 |
-
|
| 78 |
btn.click(ai_tutor, inputs=[inp], outputs=[out_txt, out_aud])
|
| 79 |
|
| 80 |
demo.launch()
|
|
|
|
| 6 |
import re
|
| 7 |
import os
|
| 8 |
|
| 9 |
+
# Branding
|
| 10 |
TITLE = "🇧🇩 Polymath-Bengali-Tutor"
|
| 11 |
DESC = "A Neuro-Symbolic AI Tutor for Rural Education in Bangladesh"
|
| 12 |
|
| 13 |
+
# Load Model (Fallback logic included)
|
| 14 |
+
model_id = "Qwen/Qwen2.5-1.5B-Instruct"
|
| 15 |
try:
|
|
|
|
| 16 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 17 |
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")
|
| 18 |
except:
|
|
|
|
| 19 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 20 |
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
| 21 |
|
| 22 |
+
# Logic
|
| 23 |
def safe_calculator(text):
|
| 24 |
bangla_digits = "০১২৩৪৫৬৭৮৯"
|
| 25 |
english_digits = "0123456789"
|
|
|
|
| 39 |
|
| 40 |
return None, None, []
|
| 41 |
|
|
|
|
| 42 |
def ai_tutor(user_input):
|
| 43 |
val, op, nums = safe_calculator(user_input)
|
| 44 |
|
|
|
|
| 61 |
except:
|
| 62 |
return ans, None
|
| 63 |
|
| 64 |
+
# UI LAUNCH (Removed 'theme' argument to fix error)
|
| 65 |
+
with gr.Blocks() as demo:
|
| 66 |
gr.Markdown(f"# {TITLE}")
|
| 67 |
gr.Markdown(f"### {DESC}")
|
|
|
|
| 68 |
with gr.Row():
|
| 69 |
+
inp = gr.Textbox(label="Question")
|
| 70 |
btn = gr.Button("Ask Polymath 🧠", variant="primary")
|
| 71 |
with gr.Row():
|
| 72 |
out_txt = gr.Textbox(label="Answer")
|
| 73 |
out_aud = gr.Audio(label="Voice", autoplay=True)
|
|
|
|
| 74 |
btn.click(ai_tutor, inputs=[inp], outputs=[out_txt, out_aud])
|
| 75 |
|
| 76 |
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
transformers
|
| 2 |
accelerate
|
| 3 |
-
gradio>=
|
| 4 |
gtts
|
| 5 |
faiss-cpu
|
| 6 |
sentence-transformers
|
|
|
|
| 1 |
transformers
|
| 2 |
accelerate
|
| 3 |
+
gradio>=3.50.0
|
| 4 |
gtts
|
| 5 |
faiss-cpu
|
| 6 |
sentence-transformers
|