Ali Abdullah commited on
Commit
f52e0e6
·
verified ·
1 Parent(s): e2cd43e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +133 -0
app.py ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+ import json
4
+ import time
5
+
6
+ # Your backend URL (you can change this to your Flask backend)
7
+ BACKEND_URL = "http://localhost:5000/api/chat" # Change this when you deploy your backend
8
+
9
+ def chat_with_bot(message, history):
10
+ """
11
+ Function to handle chat with the bot
12
+ """
13
+ if not message.strip():
14
+ return history, ""
15
+
16
+ # Add user message to history
17
+ history = history + [[message, None]]
18
+
19
+ try:
20
+ # Simulate typing delay
21
+ time.sleep(1)
22
+
23
+ # For demo purposes, we'll create a simple response
24
+ # Replace this with actual API call to your backend
25
+ response = f"Thanks for asking about '{message}'! This is atomcamp AI assistant. I can help you with:\n\n• Data Science courses\n• Machine Learning concepts\n• Programming tutorials\n• Career guidance\n\nWhat specific topic would you like to explore?"
26
+
27
+ # You can uncomment this when you have your backend ready:
28
+ # response_data = requests.post(BACKEND_URL, json={"message": message})
29
+ # response = response_data.json().get("response", "Sorry, I couldn't process your request.")
30
+
31
+ # Add bot response to history
32
+ history[-1][1] = response
33
+
34
+ except Exception as e:
35
+ history[-1][1] = "Sorry, I'm having trouble connecting to the server. Please try again later."
36
+
37
+ return history, ""
38
+
39
+ # Custom CSS for atomcamp branding
40
+ custom_css = """
41
+ .gradio-container {
42
+ font-family: 'Inter', sans-serif !important;
43
+ }
44
+
45
+ .chat-message {
46
+ font-size: 14px !important;
47
+ }
48
+
49
+ #chatbot {
50
+ height: 500px !important;
51
+ }
52
+
53
+ .message.user {
54
+ background: linear-gradient(135deg, #22c55e, #16a34a) !important;
55
+ color: white !important;
56
+ }
57
+
58
+ .message.bot {
59
+ background: #f3f4f6 !important;
60
+ color: #374151 !important;
61
+ }
62
+
63
+ .contain {
64
+ max-width: 800px !important;
65
+ margin: 0 auto !important;
66
+ }
67
+
68
+ footer {
69
+ display: none !important;
70
+ }
71
+ """
72
+
73
+ # Create the Gradio interface
74
+ with gr.Blocks(
75
+ css=custom_css,
76
+ title="atomcamp AI Chatbot",
77
+ theme=gr.themes.Soft(
78
+ primary_hue="green",
79
+ secondary_hue="gray",
80
+ neutral_hue="gray",
81
+ )
82
+ ) as demo:
83
+
84
+ # Header
85
+ gr.HTML("""
86
+ <div style="text-align: center; padding: 2rem 0; background: linear-gradient(135deg, #f8fafc, #f1f5f9); border-radius: 10px; margin-bottom: 2rem;">
87
+ <div style="background: #22c55e; color: white; padding: 12px 24px; border-radius: 24px; display: inline-block; font-weight: 700; font-size: 18px; margin-bottom: 1rem;">
88
+ atomcamp
89
+ </div>
90
+ <h1 style="color: #166534; font-size: 2rem; font-weight: 600; margin: 0;">AI Chatbot Assistant</h1>
91
+ <p style="color: #6b7280; margin-top: 0.5rem;">Ask me about data science, courses, and learning paths!</p>
92
+ </div>
93
+ """)
94
+
95
+ # Chat interface
96
+ chatbot = gr.Chatbot(
97
+ elem_id="chatbot",
98
+ label="Chat with atomcamp AI",
99
+ show_label=False,
100
+ avatar_images=["👤", "🤖"],
101
+ bubble_full_width=False,
102
+ show_share_button=False,
103
+ )
104
+
105
+ # Input area
106
+ with gr.Row():
107
+ msg = gr.Textbox(
108
+ placeholder="Ask me anything about atomcamp...",
109
+ show_label=False,
110
+ scale=4,
111
+ container=False
112
+ )
113
+ submit_btn = gr.Button("Send", variant="primary", scale=1)
114
+
115
+ # Footer info
116
+ gr.HTML("""
117
+ <div style="text-align: center; padding: 1rem; color: #6b7280; font-size: 0.875rem; margin-top: 2rem;">
118
+ <p>🚀 Built with ❤️ for atomcamp | Data Science Education Platform</p>
119
+ <p>💡 This chatbot can help you with courses, concepts, and career guidance</p>
120
+ </div>
121
+ """)
122
+
123
+ # Event handlers
124
+ msg.submit(chat_with_bot, [msg, chatbot], [chatbot, msg])
125
+ submit_btn.click(chat_with_bot, [msg, chatbot], [chatbot, msg])
126
+
127
+ # Launch the app
128
+ if __name__ == "__main__":
129
+ demo.launch(
130
+ server_name="0.0.0.0",
131
+ server_port=7860,
132
+ share=True
133
+ )