Spaces:
Sleeping
Sleeping
File size: 1,283 Bytes
3434053 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
import random
import time
# Dummy knowledge base
FAQ = {
"hello": ["Hi there!", "Hello! How can I help you?"],
"bye": ["Goodbye π", "See you soon!"],
"help": ["Ask me anything about our products.", "Try typing 'pricing' or 'features'."],
"pricing": ["Our plans start at $9/month.", "Check the website for the latest pricing."],
"features": ["We support file uploads, integrations, and real-time sync.", "Explore the docs for the full list."],
}
def respond(message: str, history: list[tuple[str, str]]):
"""Return a response based on simple keyword matching."""
message = message.strip().lower()
response = None
# Simple keyword lookup
for key in FAQ:
if key in message:
response = random.choice(FAQ[key])
break
# Fallback
response = response or "I'm not sure how to answer that. Could you rephrase?"
# Simulate typing delay
time.sleep(random.uniform(0.3, 1.2))
return response
# Build and launch the interface
demo = gr.ChatInterface(
fn=respond,
title="Simple FAQ Bot",
description="Ask me about pricing, features, or just say hello!",
theme="soft",
examples=["hello", "pricing", "features"],
)
if __name__ == "__main__":
demo.launch() |