matthartman commited on
Commit
3434053
·
verified ·
1 Parent(s): 34ba071

Upload app.py with huggingface_hub

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