Spaces:
Sleeping
Sleeping
Adedoyinjames commited on
Commit ·
6bc6acf
1
Parent(s): b74483c
Initial YAH Tech AI Space
Browse files
app.py
CHANGED
|
@@ -1,28 +1,222 @@
|
|
| 1 |
-
from sentence_transformers import SentenceTransformer
|
| 2 |
-
import faiss
|
| 3 |
-
import numpy as np
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
"""
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import json
|
| 4 |
+
from datetime import datetime
|
| 5 |
|
| 6 |
+
# Enhanced company data with more comprehensive information
|
| 7 |
+
company_knowledge = {
|
| 8 |
+
"company_info": """
|
| 9 |
+
YAH Tech is a venture studio and app development company founded by Adedoyin Ifeoluwa James.
|
| 10 |
+
We build profitable and impactful systems that drive economic growth through flexible, scalable technology.
|
| 11 |
+
Our mission is to create technology solutions that solve real-world problems while generating sustainable revenue.
|
| 12 |
+
We specialize in web development, mobile apps, AI solutions, and digital transformation services.
|
| 13 |
+
""",
|
| 14 |
+
|
| 15 |
+
"founder_info": """
|
| 16 |
+
Adedoyin Ifeoluwa James is an entrepreneur and technology innovator.
|
| 17 |
+
He is the founder and CEO of both YAH Tech and Yahcorps.
|
| 18 |
+
With a passion for economic development, he focuses on creating systems that combine profitability with social impact.
|
| 19 |
+
His vision is to leverage technology as a catalyst for sustainable economic growth in Africa and beyond.
|
| 20 |
+
""",
|
| 21 |
+
|
| 22 |
+
"services": """
|
| 23 |
+
YAH Tech offers:
|
| 24 |
+
• Custom Software Development
|
| 25 |
+
• Mobile App Development (iOS & Android)
|
| 26 |
+
• AI and Machine Learning Solutions
|
| 27 |
+
• Web Applications & E-commerce
|
| 28 |
+
• Digital Transformation Consulting
|
| 29 |
+
• Venture Building & Tech Incubation
|
| 30 |
+
""",
|
| 31 |
+
|
| 32 |
+
"contact": """
|
| 33 |
+
You can reach YAH Tech through:
|
| 34 |
+
Email: contact@yahtech.com
|
| 35 |
+
Website: www.yahtech.com
|
| 36 |
+
LinkedIn: linkedin.com/company/yahtech
|
| 37 |
+
"""
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# Enhanced response system with general knowledge
|
| 41 |
+
def get_enhanced_response(user_message, chat_history):
|
| 42 |
+
user_message_lower = user_message.lower()
|
| 43 |
+
|
| 44 |
+
# Company-specific queries
|
| 45 |
+
if any(keyword in user_message_lower for keyword in ['yah tech', 'adedoyin', 'founder', 'ceo', 'company']):
|
| 46 |
+
if 'service' in user_message_lower or 'what do you do' in user_message_lower:
|
| 47 |
+
return company_knowledge['services']
|
| 48 |
+
elif 'contact' in user_message_lower or 'email' in user_message_lower or 'website' in user_message_lower:
|
| 49 |
+
return company_knowledge['contact']
|
| 50 |
+
elif 'founder' in user_message_lower or 'adedoyin' in user_message_lower:
|
| 51 |
+
return company_knowledge['founder_info']
|
| 52 |
+
else:
|
| 53 |
+
return company_knowledge['company_info']
|
| 54 |
+
|
| 55 |
+
# General knowledge and everyday questions
|
| 56 |
+
elif any(keyword in user_message_lower for keyword in ['hello', 'hi', 'hey']):
|
| 57 |
+
return "Hello! I'm YAH Tech AI assistant. How can I help you today? Feel free to ask about YAH Tech, our services, or any general questions!"
|
| 58 |
+
|
| 59 |
+
elif any(keyword in user_message_lower for keyword in ['how are you', 'how do you do']):
|
| 60 |
+
return "I'm functioning well, thank you! I'm here to assist you with information about YAH Tech and answer your general questions. What would you like to know?"
|
| 61 |
+
|
| 62 |
+
elif any(keyword in user_message_lower for keyword in ['time', 'date']):
|
| 63 |
+
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
| 64 |
+
return f"The current date and time is: {current_time}"
|
| 65 |
+
|
| 66 |
+
elif any(keyword in user_message_lower for keyword in ['weather']):
|
| 67 |
+
return "I don't have real-time weather data, but I recommend checking a weather service for current conditions in your area."
|
| 68 |
+
|
| 69 |
+
elif any(keyword in user_message_lower for keyword in ['thank you', 'thanks']):
|
| 70 |
+
return "You're welcome! Is there anything else I can help you with?"
|
| 71 |
+
|
| 72 |
+
elif any(keyword in user_message_lower for keyword in ['bye', 'goodbye', 'see you']):
|
| 73 |
+
return "Goodbye! Thank you for chatting with YAH Tech AI. Feel free to return if you have more questions!"
|
| 74 |
+
|
| 75 |
+
elif any(keyword in user_message_lower for keyword in ['what can you do', 'help']):
|
| 76 |
+
return """I can help you with:
|
| 77 |
+
• Information about YAH Tech and our services
|
| 78 |
+
• Details about our founder Adedoyin Ifeoluwa James
|
| 79 |
+
• Answer general questions and have conversations
|
| 80 |
+
• Provide basic assistance with everyday queries
|
| 81 |
+
• Discuss technology, entrepreneurship, and business
|
| 82 |
+
|
| 83 |
+
What would you like to know?"""
|
| 84 |
+
|
| 85 |
+
elif any(keyword in user_message_lower for keyword in ['technology', 'tech']):
|
| 86 |
+
return "Technology is transforming every industry! At YAH Tech, we believe in leveraging cutting-edge technologies like AI, cloud computing, and mobile platforms to create innovative solutions that drive growth and efficiency."
|
| 87 |
+
|
| 88 |
+
elif any(keyword in user_message_lower for keyword in ['entrepreneur', 'business']):
|
| 89 |
+
return "Entrepreneurship is about identifying opportunities and creating value. Successful businesses often combine innovation with market needs. YAH Tech operates as a venture studio, helping to build and scale new technology ventures."
|
| 90 |
+
|
| 91 |
+
# Fallback response for unknown queries
|
| 92 |
+
else:
|
| 93 |
+
return f"I understand you're asking about: '{user_message}'. While I'm primarily focused on YAH Tech information, I can tell you that this seems like an interesting topic. For detailed information, you might want to consult specialized resources. Is there anything specific about YAH Tech or general technology/business topics I can help with?"
|
| 94 |
+
|
| 95 |
+
def chat_interface(message, chat_history):
|
| 96 |
+
bot_response = get_enhanced_response(message, chat_history)
|
| 97 |
+
|
| 98 |
+
# Format the conversation
|
| 99 |
+
chat_history.append([message, bot_response])
|
| 100 |
+
|
| 101 |
+
return "", chat_history
|
| 102 |
+
|
| 103 |
+
# Custom CSS for ChatGPT-like appearance
|
| 104 |
+
custom_css = """
|
| 105 |
+
.chat-container {
|
| 106 |
+
max-height: 500px;
|
| 107 |
+
overflow-y: auto;
|
| 108 |
+
border: 1px solid #e0e0e0;
|
| 109 |
+
border-radius: 10px;
|
| 110 |
+
padding: 20px;
|
| 111 |
+
background: #f9f9f9;
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
.user-message {
|
| 115 |
+
background: #007bff;
|
| 116 |
+
color: white;
|
| 117 |
+
padding: 10px 15px;
|
| 118 |
+
border-radius: 18px 18px 0 18px;
|
| 119 |
+
margin: 5px 0;
|
| 120 |
+
max-width: 80%;
|
| 121 |
+
margin-left: auto;
|
| 122 |
+
}
|
| 123 |
|
| 124 |
+
.bot-message {
|
| 125 |
+
background: #e9ecef;
|
| 126 |
+
color: #333;
|
| 127 |
+
padding: 10px 15px;
|
| 128 |
+
border-radius: 18px 18px 18px 0;
|
| 129 |
+
margin: 5px 0;
|
| 130 |
+
max-width: 80%;
|
| 131 |
+
margin-right: auto;
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
.chat-input {
|
| 135 |
+
border-radius: 25px;
|
| 136 |
+
padding: 12px 20px;
|
| 137 |
+
border: 2px solid #007bff;
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
.send-button {
|
| 141 |
+
border-radius: 25px;
|
| 142 |
+
background: #007bff;
|
| 143 |
+
color: white;
|
| 144 |
+
border: none;
|
| 145 |
+
padding: 12px 30px;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
.title {
|
| 149 |
+
text-align: center;
|
| 150 |
+
color: #2c3e50;
|
| 151 |
+
font-weight: bold;
|
| 152 |
+
margin-bottom: 20px;
|
| 153 |
+
}
|
| 154 |
+
|
| 155 |
+
.gradio-container {
|
| 156 |
+
max-width: 800px !important;
|
| 157 |
+
margin: 0 auto;
|
| 158 |
+
}
|
| 159 |
"""
|
| 160 |
|
| 161 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
| 162 |
+
gr.Markdown(
|
| 163 |
+
"""
|
| 164 |
+
# <div class="title">YAH Tech AI Assistant</div>
|
| 165 |
+
<div style="text-align: center; color: #666; margin-bottom: 20px;">
|
| 166 |
+
Powered by advanced AI • Ask me about YAH Tech or general questions
|
| 167 |
+
</div>
|
| 168 |
+
"""
|
| 169 |
+
)
|
| 170 |
+
|
| 171 |
+
chatbot = gr.Chatbot(
|
| 172 |
+
label="Chat",
|
| 173 |
+
elem_classes="chat-container",
|
| 174 |
+
show_label=False,
|
| 175 |
+
height=500
|
| 176 |
+
)
|
| 177 |
+
|
| 178 |
+
with gr.Row():
|
| 179 |
+
msg = gr.Textbox(
|
| 180 |
+
placeholder="Type your message here...",
|
| 181 |
+
show_label=False,
|
| 182 |
+
scale=4,
|
| 183 |
+
elem_classes="chat-input"
|
| 184 |
+
)
|
| 185 |
+
send = gr.Button("Send", variant="primary", scale=1, elem_classes="send-button")
|
| 186 |
+
clear = gr.Button("Clear", variant="secondary", scale=1)
|
| 187 |
+
|
| 188 |
+
# Footer
|
| 189 |
+
gr.Markdown(
|
| 190 |
+
"""
|
| 191 |
+
<div style="text-align: center; margin-top: 20px; color: #888; font-size: 12px;">
|
| 192 |
+
YAH Tech AI Assistant • Building the future of technology
|
| 193 |
+
</div>
|
| 194 |
+
"""
|
| 195 |
+
)
|
| 196 |
+
|
| 197 |
+
def clear_chat():
|
| 198 |
+
return []
|
| 199 |
+
|
| 200 |
+
msg.submit(
|
| 201 |
+
chat_interface,
|
| 202 |
+
inputs=[msg, chatbot],
|
| 203 |
+
outputs=[msg, chatbot]
|
| 204 |
+
)
|
| 205 |
+
|
| 206 |
+
send.click(
|
| 207 |
+
chat_interface,
|
| 208 |
+
inputs=[msg, chatbot],
|
| 209 |
+
outputs=[msg, chatbot]
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
clear.click(
|
| 213 |
+
clear_chat,
|
| 214 |
+
outputs=[chatbot]
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
if __name__ == "__main__":
|
| 218 |
+
demo.launch(
|
| 219 |
+
share=False,
|
| 220 |
+
server_name="0.0.0.0",
|
| 221 |
+
server_port=7860
|
| 222 |
+
)
|