akhaliq HF Staff commited on
Commit
4fd8404
·
verified ·
1 Parent(s): 6a37a92

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +163 -0
  2. requirements.txt +14 -0
app.py ADDED
@@ -0,0 +1,163 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from utils import get_chatbot_response
3
+ import random
4
+
5
+ def chat_response(message, history):
6
+ """
7
+ Process user message and generate chatbot response
8
+
9
+ Args:
10
+ message (str): User's input message
11
+ history (list): Chat history for context
12
+
13
+ Returns:
14
+ str: Generated response from the chatbot
15
+ """
16
+ if not message.strip():
17
+ return "Please enter a message to chat!"
18
+
19
+ # Get response from the utility function
20
+ response = get_chatbot_response(message, history)
21
+
22
+ return response
23
+
24
+ def clear_chat():
25
+ """Clear the chat history"""
26
+ return []
27
+
28
+ def refresh_suggestions():
29
+ """Generate new conversation starters"""
30
+ suggestions = [
31
+ "What's the weather like today?",
32
+ "Tell me a joke",
33
+ "How does artificial intelligence work?",
34
+ "What are some productivity tips?",
35
+ "Explain quantum computing simply",
36
+ "What are the latest trends in technology?",
37
+ "How can I learn programming?",
38
+ "What's the meaning of life?",
39
+ "Tell me about space exploration",
40
+ "What are some good books to read?"
41
+ ]
42
+ return random.choice(suggestions)
43
+
44
+ # Create the Gradio Blocks interface
45
+ with gr.Blocks(
46
+ title="AI Chatbot",
47
+ theme=gr.themes.Soft(
48
+ primary_hue="blue",
49
+ secondary_hue="gray",
50
+ font=[gr.themes.GoogleFont("Inter"), "Arial", "sans-serif"]
51
+ ),
52
+ css="""
53
+ .gradio-container {max-width: 1200px !important;}
54
+ .chatbot-container {height: 600px !important;}
55
+ .header-text {text-align: center; margin-bottom: 20px;}
56
+ .footer-text {text-align: center; margin-top: 20px; color: #666;}
57
+ """,
58
+ title="Intelligent Chatbot"
59
+ ) as demo:
60
+
61
+ # Header
62
+ gr.HTML("""
63
+ <div class="header-text">
64
+ <h1>🤖 AI Chatbot</h1>
65
+ <p>Welcome! I'm your intelligent assistant. Ask me anything!</p>
66
+ <p><a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #007bff; text-decoration: none;">Built with anycoder</a></p>
67
+ </div>
68
+ """)
69
+
70
+ # Main chat interface
71
+ with gr.Row():
72
+ with gr.Column(scale=3):
73
+ chat_interface = gr.ChatInterface(
74
+ fn=chat_response,
75
+ title="",
76
+ description="",
77
+ examples=[
78
+ "Hello! How are you?",
79
+ "What's the weather like?",
80
+ "Tell me a joke",
81
+ "Explain AI in simple terms",
82
+ "What are some productivity tips?",
83
+ "How do I learn programming?",
84
+ "What's the meaning of life?",
85
+ "Tell me about space",
86
+ "What books do you recommend?",
87
+ "How does the internet work?"
88
+ ],
89
+ example_labels=[
90
+ "Greeting", "Weather", "Joke", "AI Explanation", "Productivity",
91
+ "Programming", "Philosophy", "Space", "Books", "Technology"
92
+ ],
93
+ retry_btn="Send Again ↻",
94
+ undo_btn="Undo Last Message ↶",
95
+ clear_btn="Clear Chat 🗑️",
96
+ submit_btn="Send ➤"
97
+ )
98
+
99
+ with gr.Column(scale=1):
100
+ # Side panel with conversation starters and info
101
+ gr.HTML("""
102
+ <div style="background: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
103
+ <h3>💬 Conversation Starters</h3>
104
+ </div>
105
+ """)
106
+
107
+ conversation_starters = gr.Examples(
108
+ examples=[
109
+ ["Tell me a joke", "What makes you laugh?"],
110
+ ["What's your favorite topic?", "I love discussing technology!"],
111
+ ["How can I be productive?", "Time management is key!"],
112
+ ["What should I learn today?", "Learning is lifelong!"],
113
+ ["Explain something interesting", "Did you know honey never spoils?"],
114
+ ],
115
+ inputs=[chat_interface.message_box],
116
+ cache_examples=False,
117
+ label="Quick Starters"
118
+ )
119
+
120
+ # Tips and info
121
+ gr.HTML("""
122
+ <div style="background: #e3f2fd; padding: 15px; border-radius: 8px; margin-top: 20px;">
123
+ <h4>💡 Tips</h4>
124
+ <ul style="margin: 10px 0; padding-left: 20px;">
125
+ <li>Ask follow-up questions for deeper conversations</li>
126
+ <li>Try different topics - I'm knowledgeable about many subjects!</li>
127
+ <li>Use the examples above to get started quickly</li>
128
+ </ul>
129
+ </div>
130
+ """)
131
+
132
+ # Chat stats
133
+ chat_stats = gr.HTML("""
134
+ <div style="background: #fff3e0; padding: 15px; border-radius: 8px; margin-top: 15px;">
135
+ <h4>📊 Chat Info</h4>
136
+ <p><strong>Model:</strong> AI Assistant v1.0</p>
137
+ <p><strong>Features:</strong> Multi-turn conversations</p>
138
+ <p><strong>Topics:</strong> General knowledge, tech, science, jokes & more!</p>
139
+ </div>
140
+ """)
141
+
142
+ # Footer
143
+ gr.HTML("""
144
+ <div class="footer-text">
145
+ <p>💬 Have a great conversation! |
146
+ <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #007bff;">Built with anycoder</a> |
147
+ <a href="#" style="color: #007bff; text-decoration: none;" onclick="window.location.reload()">Refresh Chat ↻</a></p>
148
+ </div>
149
+ """)
150
+
151
+ # Launch the application
152
+ if __name__ == "__main__":
153
+ demo.queue(
154
+ concurrency_count=3,
155
+ max_size=50,
156
+ default_concurrency_limit=1
157
+ ).launch(
158
+ share=False,
159
+ server_name="0.0.0.0",
160
+ server_port=7860,
161
+ show_error=True,
162
+ quiet=False
163
+ )
requirements.txt ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ gradio
2
+ requests
3
+ Pillow
4
+ numpy
5
+ pandas
6
+ matplotlib
7
+ plotly
8
+ markdown
9
+ pydantic
10
+ fastapi
11
+ uvicorn
12
+ aiofiles
13
+ python-multipart
14
+ websockets