Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,10 +8,6 @@ client = InferenceClient(
|
|
| 8 |
token=os.environ.get("HF_TOKEN"),
|
| 9 |
)
|
| 10 |
|
| 11 |
-
speech_client = InferenceClient(
|
| 12 |
-
model="openai/whisper-small",
|
| 13 |
-
token=os.environ.get("HF_TOKEN"),
|
| 14 |
-
)
|
| 15 |
|
| 16 |
SYSTEM_PROMPT = """You are an expert WhatsApp reply assistant for small shop owners in India.
|
| 17 |
Your job is to draft short, warm, professional replies that sound like a real shopkeeper — not a robot.
|
|
@@ -70,26 +66,6 @@ No markdown, no bullet points. Just the reply text."""
|
|
| 70 |
except Exception as e:
|
| 71 |
return f"❌ Error: {str(e)}\n\nMake sure HF_TOKEN is set in your Space secrets."
|
| 72 |
|
| 73 |
-
def transcribe_audio(audio_path):
|
| 74 |
-
print("Audio received:", audio_path)
|
| 75 |
-
|
| 76 |
-
if audio_path is None:
|
| 77 |
-
return ""
|
| 78 |
-
|
| 79 |
-
try:
|
| 80 |
-
with open(audio_path, "rb") as audio_file:
|
| 81 |
-
result = speech_client.audio_to_text(audio_file)
|
| 82 |
-
|
| 83 |
-
print("Result:", result)
|
| 84 |
-
|
| 85 |
-
if hasattr(result, "text"):
|
| 86 |
-
return result.text
|
| 87 |
-
|
| 88 |
-
return str(result)
|
| 89 |
-
|
| 90 |
-
except Exception as e:
|
| 91 |
-
print("VOICE ERROR:", repr(e))
|
| 92 |
-
return f"Voice transcription failed: {repr(e)}"
|
| 93 |
|
| 94 |
# ── CSS ──────────────────────────────────────────────────────────────────────
|
| 95 |
css = """
|
|
@@ -392,11 +368,6 @@ with gr.Blocks(title="Dukaan Saathi – AI Reply Assistant") as demo:
|
|
| 392 |
with gr.Column(scale=6, elem_classes="panel"):
|
| 393 |
gr.Markdown("**CUSTOMER'S WHATSAPP MESSAGE**", elem_classes="section-label")
|
| 394 |
|
| 395 |
-
voice_input = gr.Audio(
|
| 396 |
-
sources=["microphone", "upload"],
|
| 397 |
-
type="filepath",
|
| 398 |
-
label="🎤 Record or Upload Voice Message"
|
| 399 |
-
)
|
| 400 |
|
| 401 |
customer_message = gr.Textbox(
|
| 402 |
label="Paste the message here",
|
|
@@ -487,11 +458,6 @@ with gr.Blocks(title="Dukaan Saathi – AI Reply Assistant") as demo:
|
|
| 487 |
</div>
|
| 488 |
""")
|
| 489 |
|
| 490 |
-
voice_input.change(
|
| 491 |
-
fn=transcribe_audio,
|
| 492 |
-
inputs=voice_input,
|
| 493 |
-
outputs=customer_message
|
| 494 |
-
)
|
| 495 |
|
| 496 |
generate_btn.click(
|
| 497 |
fn=generate_reply,
|
|
|
|
| 8 |
token=os.environ.get("HF_TOKEN"),
|
| 9 |
)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
SYSTEM_PROMPT = """You are an expert WhatsApp reply assistant for small shop owners in India.
|
| 13 |
Your job is to draft short, warm, professional replies that sound like a real shopkeeper — not a robot.
|
|
|
|
| 66 |
except Exception as e:
|
| 67 |
return f"❌ Error: {str(e)}\n\nMake sure HF_TOKEN is set in your Space secrets."
|
| 68 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
# ── CSS ──────────────────────────────────────────────────────────────────────
|
| 71 |
css = """
|
|
|
|
| 368 |
with gr.Column(scale=6, elem_classes="panel"):
|
| 369 |
gr.Markdown("**CUSTOMER'S WHATSAPP MESSAGE**", elem_classes="section-label")
|
| 370 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
customer_message = gr.Textbox(
|
| 373 |
label="Paste the message here",
|
|
|
|
| 458 |
</div>
|
| 459 |
""")
|
| 460 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
|
| 462 |
generate_btn.click(
|
| 463 |
fn=generate_reply,
|