Spaces:
Sleeping
Sleeping
update app
Browse files
app.py
CHANGED
@@ -21,4 +21,31 @@ def respond(user_input):
|
|
21 |
# Generate AI response
|
22 |
prompt = f"[INST] {user_input} [/INST]"
|
23 |
inputs = tokenizer(prompt, return_tensors="pt")
|
24 |
-
outputs = model.generate(**inputs,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
# Generate AI response
|
22 |
prompt = f"[INST] {user_input} [/INST]"
|
23 |
inputs = tokenizer(prompt, return_tensors="pt")
|
24 |
+
outputs = model.generate(**inputs, max_new_tokens=256, pad_token_id=tokenizer.eos_token_id)
|
25 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
26 |
+
|
27 |
+
# Convert to speech
|
28 |
+
try:
|
29 |
+
tts = gTTS(text=response, lang='hi' if detected_lang == 'hi' else 'en')
|
30 |
+
with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as fp:
|
31 |
+
tts.save(fp.name)
|
32 |
+
audio_path = fp.name
|
33 |
+
except Exception as e:
|
34 |
+
audio_path = None
|
35 |
+
|
36 |
+
return response, audio_path
|
37 |
+
|
38 |
+
# UI
|
39 |
+
iface = gr.Interface(
|
40 |
+
fn=respond,
|
41 |
+
inputs=gr.Textbox(lines=2, placeholder="Ask anything...", label="user_input"),
|
42 |
+
outputs=[
|
43 |
+
gr.Textbox(label="TeachMe Says"),
|
44 |
+
gr.Audio(label="Voice", type="filepath", autoplay=True)
|
45 |
+
],
|
46 |
+
title="TeachMe - Your Smart Tutor",
|
47 |
+
description="Light AI bot with Hindi + English voice support."
|
48 |
+
)
|
49 |
+
|
50 |
+
iface.launch()
|
51 |
+
|