├── HarryPorterSearch ├── main.py ├── hp_search_engine.py ├── README.md └── gui.py └── ChatbotUsingPython ├── README.md └── main.py /HarryPorterSearch/main.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtWidgets import QApplication 2 | import sys 3 | from gui import BookSearchGUI 4 | 5 | def main(): 6 | app = QApplication(sys.argv) 7 | window = BookSearchGUI() 8 | window.show() 9 | sys.exit(app.exec_()) 10 | 11 | if __name__ == "__main__": 12 | main() 13 | -------------------------------------------------------------------------------- /HarryPorterSearch/hp_search_engine.py: -------------------------------------------------------------------------------- 1 | import os 2 | import re 3 | 4 | class SearchResult: 5 | def __init__(self, name, page, chapter, book, paragraph_index): 6 | self.name = name 7 | self.page = page 8 | self.chapter = chapter 9 | self.book = book 10 | self.paragraph_index = paragraph_index 11 | 12 | class BookParser: 13 | def __init__(self, book_path): 14 | self.book_path = book_path 15 | self.book_title = os.path.basename(book_path).replace('.txt', '') 16 | self.paragraphs = [] 17 | self.load_book() 18 | 19 | def load_book(self): 20 | with open(self.book_path, encoding="utf-8") as f: 21 | text = f.read() 22 | self.paragraphs = [p.strip() for p in text.split('\n\n') if p.strip()] 23 | 24 | def search(self, keyword): 25 | results = [] 26 | chapter, page = "Unknown", 1 27 | for i, paragraph in enumerate(self.paragraphs): 28 | if re.search(rf'\b{re.escape(keyword)}\b', paragraph, re.IGNORECASE): 29 | results.append(SearchResult(keyword, page, chapter, self.book_title, i)) 30 | if i % 5 == 0: 31 | page += 1 32 | return results 33 | 34 | def get_context(self, index): 35 | prev = self.paragraphs[index - 1] if index > 0 else "" 36 | curr = self.paragraphs[index] 37 | next_p = self.paragraphs[index + 1] if index + 1 < len(self.paragraphs) else "" 38 | return prev, curr, next_p 39 | -------------------------------------------------------------------------------- /HarryPorterSearch/README.md: -------------------------------------------------------------------------------- 1 | # 📚 Harry Potter Book Search GUI 2 | 3 | A desktop application built with **Python** and **PyQt5** that allows you to search through Harry Potter books for character names, places, or any keywords, and view the surrounding context. 4 | 5 | --- 6 | 7 | ## ✨ Features 8 | - **Search by keyword** (e.g., "Harry", "Dumbledore", "Hogwarts") 9 | - **Multi-book search**: Scans all `.txt` files in the `books/` folder 10 | - **Results list** with book title, page, and chapter 11 | - **Context view**: Displays previous, matching, and next paragraphs 12 | - **Simple, user-friendly PyQt5 interface** 13 | 14 | --- 15 | 16 | ## 📂 Project Structure 17 | HarryPotterSearch/ 18 | ├── main.py # Application entry point 19 | ├── gui.py # PyQt5 GUI implementation 20 | ├── hp_search_engine.py # Search and parsing logic 21 | ├── books/ # Folder containing book text files (.txt) 22 | └── README.md # Documentation 23 | 24 | --- 25 | 26 | ## 🛠 Requirements 27 | - **Python 3.7+** 28 | - **PyQt5** for GUI 29 | Install dependencies: 30 | pip install PyQt5 31 | ## How to Run 32 | 1. Prepare the books folder 33 | 34 | Create a folder named books in the project directory. 35 | 36 | Add Harry Potter .txt book files into the books folder. 37 | 38 | 2. Run the application 39 | python main.py 40 | 3. Search for a keyword 41 | 42 | Type a character or place name in the search box. 43 | 44 | Click Search or press Enter. 45 | 46 | Select a result to view its context. 47 | ## Example 48 | If you search for: 49 | Harry 50 | You’ll see a list like: 51 | 1. Harry | Page 2, Chapter Unknown, Book: Sorcerer's Stone 52 | 2. Harry | Page 3, Chapter Unknown, Book: Sorcerer's Stone 53 | 54 | ...Selecting a result shows: 55 | 🧾 Previous: 56 | [Paragraph before match] 57 | 58 | 📍 Match: 59 | [Paragraph containing "Harry"] 60 | 61 | ➡️ Next: 62 | [Paragraph after match] 63 | 64 | ## How It Works 65 | hp_search_engine.py 66 | 67 | BookParser loads the text, splits it into paragraphs, and searches for exact keyword matches. 68 | 69 | Returns SearchResult objects containing keyword, page, chapter, book title, and paragraph index. 70 | 71 | Provides context (previous, current, next paragraphs) for each match. 72 | 73 | gui.py 74 | 75 | Handles the PyQt5 interface, including search input, results list, and context display. 76 | 77 | Manages the connection between user actions and search results. 78 | 79 | main.py 80 | 81 | Launches the application. 82 | ## License 83 | This project is open-source and free for educational purposes. 84 | 85 | ## Author 86 | Developed by Ruhit Shah 87 | Built with Python and PyQt5 for book search and analysis. 88 | -------------------------------------------------------------------------------- /ChatbotUsingPython/README.md: -------------------------------------------------------------------------------- 1 | # 💬 Simple Keyword-Based Chatbot (Python) 2 | This is a basic Python chatbot that uses a predefined dataset of intents, keywords, and responses to interact with users. It can respond to greetings, pricing inquiries, technical issues, services, and goodbyes — or prompt the user for clarification when it doesn’t understand. 3 | ## 📌 Features 4 | - Predefined intents: greeting, pricing, technical issues, services, goodbyes, and unknown queries. 5 | - Keyword matching to detect user intent. 6 | - Randomized responses for a more natural conversation. 7 | - Exit command to end the chat anytime. 8 | ## 📂 Project Structure 9 | SimpleChatbot/ 10 | ├── main.py # Main Python script 11 | ├── README.md # Project documentation 12 | ## 🛠 Requirements 13 | - Python 3.6 or higher 14 | No additional external libraries are required (uses only Python’s standard library). 15 | ## 🚀 How to Run 16 | 1. Clone the repository 17 | git clone https://github.com/yourusername/simple-chatbot.git 18 | cd simple-chatbot 19 | 2. Run the chatbot 20 | python chatbot.py 21 | ## Example interaction 22 | Chatbot: Hello! Welcome to our software firm. How can I help you today? 23 | You: hi 24 | Chatbot: Hi there! Need help with something? 25 | You: pricing 26 | Chatbot: Our pricing depends on your requirements. Would you like to discuss details? 27 | You: exit 28 | Chatbot: Goodbye! Have a great day! 29 | | Intent | Keywords | Example User Input | 30 | | --------------- | ---------------------------------- | ----------------------------- | 31 | | Greeting | hello, hi, greetings, hey | "hello" | 32 | | Pricing | price, cost, pricing, charge | "What’s the price?" | 33 | | Technical Issue | issue, problem, bug, error | "I found a bug" | 34 | | Services | service, offer, solutions, product | "What services do you offer?" | 35 | | Goodbye | bye, goodbye, see you, exit | "bye" | 36 | | Unknown | (anything else) | "Tell me a joke" | 37 | ## How It Works 38 | Intent Identification: Scans the user input for keywords and matches them to predefined intents in dataset. 39 | 40 | Response Generation: Randomly picks a response from the intent’s list of possible replies. 41 | 42 | Unknown Handling: If no keywords match, returns a generic clarification request. 43 | 44 | ## License 45 | This project is open-source for educational purposes. You can modify and extend it freely. 46 | 47 | ## Author 48 | Developed by Ruhit Shah as a learning project in Python chatbot development. 49 | -------------------------------------------------------------------------------- /ChatbotUsingPython/main.py: -------------------------------------------------------------------------------- 1 | 2 | dataset = { 3 | "greeting": { 4 | "keywords": ["hello", "hi", "greetings", "hey"], 5 | "responses": ["Hello! How can I assist you today?", 6 | "Hi there! Need help with something?"] 7 | }, 8 | "pricing": { 9 | "keywords": ["price", "cost", "pricing", "charge"], 10 | "responses": ["Our pricing depends on your requirements. Would you like to discuss details?", 11 | "You can check our pricing plans on our website. Do you need a link?"] 12 | }, 13 | "technical_issue": { 14 | "keywords": ["issue", "problem", "bug", "error"], 15 | "responses": ["I'm sorry to hear about the issue. Can you describe the problem?", 16 | "Let me assist you with the issue. Please provide more details."] 17 | }, 18 | "services": { 19 | "keywords": ["service", "offer", "solutions", "product"], 20 | "responses": ["We offer software development, system integration, and maintenance services.", 21 | "Our services include web development, mobile apps, and cloud solutions. What are you looking for?"] 22 | }, 23 | "goodbye": { 24 | "keywords": ["bye", "goodbye", "see you", "exit"], 25 | "responses": ["Goodbye! Feel free to reach out anytime.", 26 | "Take care! We’re here if you need us."] 27 | }, 28 | "unknown": { 29 | "responses": ["I'm sorry, I didn't understand that. Could you please rephrase?", 30 | "Can you provide more details? I'm here to help."] 31 | } 32 | } 33 | 34 | # NLU function to identify user intent based on keywords 35 | def identify_intent(user_input): 36 | for intent, data in dataset.items(): 37 | if intent != "unknown": 38 | for keyword in data["keywords"]: 39 | if keyword.lower() in user_input.lower(): 40 | return intent 41 | return "unknown" 42 | 43 | # Function to generate response 44 | import random 45 | 46 | def generate_response(intent): 47 | return random.choice(dataset[intent]["responses"]) 48 | 49 | # Chatbot function 50 | def chatbot(): 51 | print("Chatbot: Hello! Welcome to our software firm. How can I help you today?") 52 | while True: 53 | user_input = input("You: ").strip() 54 | if user_input.lower() in ["exit", "quit"]: 55 | print("Chatbot: Goodbye! Have a great day!") 56 | break 57 | # Identify intent 58 | intent = identify_intent(user_input) 59 | # Generate response 60 | response = generate_response(intent) 61 | print(f"Chatbot: {response}") 62 | 63 | # Run the chatbot 64 | if __name__ == "__main__": 65 | chatbot() 66 | -------------------------------------------------------------------------------- /HarryPorterSearch/gui.py: -------------------------------------------------------------------------------- 1 | from PyQt5.QtWidgets import ( 2 | QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit, 3 | QPushButton, QTextEdit, QListWidget, QListWidgetItem, QHBoxLayout 4 | ) 5 | from PyQt5.QtGui import QFont, QColor, QPalette 6 | from PyQt5.QtCore import Qt 7 | import os 8 | from hp_search_engine import BookParser 9 | 10 | class BookSearchGUI(QWidget): 11 | def __init__(self, books_folder="books"): 12 | super().__init__() 13 | self.setWindowTitle("🔍 Harry Potter Search Interface") 14 | self.resize(900, 650) 15 | 16 | # Set font and palette 17 | self.setFont(QFont("Segoe UI", 10)) 18 | palette = QPalette() 19 | palette.setColor(QPalette.Window, QColor("#f7f7f7")) 20 | self.setPalette(palette) 21 | 22 | # Layout setup 23 | self.layout = QVBoxLayout() 24 | self.setLayout(self.layout) 25 | 26 | # Header 27 | title_label = QLabel("📚 Harry Potter Book Search") 28 | title_label.setFont(QFont("Georgia", 16, QFont.Bold)) 29 | title_label.setAlignment(Qt.AlignCenter) 30 | self.layout.addWidget(title_label) 31 | 32 | # Search input section 33 | search_layout = QHBoxLayout() 34 | self.search_input = QLineEdit() 35 | self.search_input.setPlaceholderText("Type a character or place name (e.g., Harry, Dumbledore, Hogwarts)") 36 | self.search_input.setFont(QFont("Segoe UI", 11)) 37 | search_layout.addWidget(self.search_input) 38 | 39 | self.search_button = QPushButton("🔍 Search") 40 | self.search_button.setFixedWidth(100) 41 | search_layout.addWidget(self.search_button) 42 | self.layout.addLayout(search_layout) 43 | 44 | # Results list 45 | self.layout.addWidget(QLabel("🔎 Matching Results:")) 46 | self.result_list = QListWidget() 47 | self.result_list.setFont(QFont("Consolas", 10)) 48 | self.layout.addWidget(self.result_list) 49 | 50 | # Context view 51 | self.layout.addWidget(QLabel("📄 Context View:")) 52 | self.result_view = QTextEdit() 53 | self.result_view.setReadOnly(True) 54 | self.result_view.setFont(QFont("Cambria", 11)) 55 | self.layout.addWidget(self.result_view) 56 | 57 | # Parser setup 58 | self.parsers = [BookParser(os.path.join(books_folder, f)) 59 | for f in os.listdir(books_folder) if f.endswith(".txt")] 60 | self.all_results = [] 61 | 62 | # Connect events 63 | self.search_button.clicked.connect(self.perform_search) 64 | self.result_list.itemClicked.connect(self.show_context) 65 | 66 | def perform_search(self): 67 | keyword = self.search_input.text().strip() 68 | if not keyword: 69 | self.result_view.setText("⚠️ Please enter a name or place to search.") 70 | return 71 | 72 | self.all_results = [] 73 | self.result_list.clear() 74 | for parser in self.parsers: 75 | results = parser.search(keyword) 76 | self.all_results.extend([(r, parser) for r in results]) 77 | 78 | if not self.all_results: 79 | self.result_list.addItem("No matches found.") 80 | else: 81 | for i, (result, _) in enumerate(self.all_results): 82 | item = QListWidgetItem(f"{i+1}. {result.name} | Page {result.page}, Chapter {result.chapter}, Book: {result.book}") 83 | item.setFont(QFont("Segoe UI", 10, QFont.Bold)) 84 | self.result_list.addItem(item) 85 | 86 | def show_context(self, item): 87 | index = self.result_list.row(item) 88 | if index >= len(self.all_results): 89 | return 90 | result, parser = self.all_results[index] 91 | prev, curr, next_p = parser.get_context(result.paragraph_index) 92 | 93 | self.result_view.setText(f"🧾 Previous:\n{prev}\n\n📍 Match:\n{curr}\n\n➡️ Next:\n{next_p}") 94 | --------------------------------------------------------------------------------