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()