AI2.0 / app.py
MonsterBoyTabs's picture
Update app.py
0bfb1ee verified
import streamlit as st
# Set the title of the app
st.title("Urdu AI Chatbot 🤖")
# Define intents and responses (keyword-based)
intents = {
"greeting": {
"keywords": ["ہیلو", "سلام", "آداب", "حال", "کیسے ہو", "کیسے ہیں"],
"response": "السلام علیکم! میں ٹھیک ہوں، شکریہ۔ آپ کیسے ہیں؟"
},
"farewell": {
"keywords": ["الوداع", "خدا حافظ", "بعد میں ملتے ہیں"],
"response": "خدا حافظ! آپ کا دن اچھا گزرے۔"
},
"thanks": {
"keywords": ["شکریہ", "بہت شکریہ", "مہربانی"],
"response": "خوش آمدید! کیا میں آپ کی مزید مدد کر سکتا ہوں؟"
}
}
# Function to detect intent using keywords
def detect_intent(user_input):
user_input = user_input.lower()
for intent, data in intents.items():
for keyword in data["keywords"]:
if keyword in user_input:
return intent
return "unknown"
# Initialize chat history
if "chat_history" not in st.session_state:
st.session_state.chat_history = []
# User input
user_input = st.text_input("آپ کا پیغام یہاں لکھیں:", "ہیلو، آپ کیسے ہیں؟")
# Send button
if st.button("بھیجیں"):
if user_input:
# Add user message to chat history
st.session_state.chat_history.append(f"آپ: {user_input}")
# Detect intent using keywords (no model needed)
intent = detect_intent(user_input)
# Get response based on intent
if intent != "unknown":
response = intents[intent]["response"]
else:
response = "معذرت، میں اس سوال کا جواب نہیں دے سکتا۔ براہ کرم ایک آسان سوال پوچھیں۔"
# Add AI response to chat history
st.session_state.chat_history.append(f"AI: {response}")
else:
st.warning("براہ کرم ایک پیغام لکھیں۔")
# Display chat history
st.write("چیٹ کی تاریخ:")
for message in st.session_state.chat_history:
st.write(message)