KraTUZen commited on
Commit
be9f39f
·
1 Parent(s): 1ac12bc
Files changed (1) hide show
  1. README.md +9 -204
README.md CHANGED
@@ -1,205 +1,10 @@
1
- # LogicLink: Version 5
2
-
3
- LogicLink is a conversational AI chatbot developed by **Kratu Gautam**, an **AIML Engineer**. Powered by the **TinyLlama-1.1B-Chat-v1.0** model, LogicLink provides an interactive and user-friendly interface for engaging conversations, answering queries, and assisting with tasks like planning, writing, and more. Version 5 introduces a sleek GUI, streaming responses, and enhanced features like conversation management.
4
-
5
- ## Features
6
-
7
- - **Conversational AI**: Built on TinyLlama-1.1B-Chat-v1.0, LogicLink delivers natural and engaging responses to a wide range of user queries.
8
- - **Streaming Responses**: Utilizes `TextIteratorStreamer` for real-time response generation, providing a smooth user experience.
9
- - **Customizable GUI**: Features a modern interface with a red/blue/black theme, powered by Gradio and ModelScope Studio components (`pro.Chatbot`, `antdx.Sender`).
10
- - **Conversation Management**:
11
- - **New Chat**: Start fresh conversations with a dedicated button.
12
- - **Clear History**: Reset the current conversation’s history.
13
- - **Delete Conversations**: Remove individual conversations from the conversation list.
14
- - **Single Time Stamp**: Responses include a single processing time stamp (e.g., `*(4.50s)*`), fixed to avoid duplication.
15
- - **CUDA Support**: Optimizes performance on GPU-enabled systems, with fallback to CPU.
16
- - **Error Handling**: Gracefully handles issues like memory shortages or invalid inputs, displaying user-friendly error messages.
17
-
18
- ## Installation
19
-
20
- ### Prerequisites
21
-
22
- - Python 3.8+
23
- - CUDA-enabled GPU (optional, for faster processing)
24
- - Dependencies:
25
-
26
- ```bash
27
- pip install gradio torch transformers modelscope-studio
28
- ```
29
-
30
- ### Setup
31
-
32
- 1. **Clone the Repository**:
33
-
34
- ```bash
35
- git clone Kratugautam99/LogicLink-Project.git
36
- cd LogicLink-Project
37
- ```
38
-
39
- 2. **Install Dependencies**:
40
-
41
- ```bash
42
- pip install -r requirements.txt
43
- ```
44
-
45
- 3. **Directory Structure**: Ensure the following files are present:
46
-
47
- - `app.py`: Main application script.
48
- - `config.py`: Configuration for GUI components (ensure `DEFAULT_LOCALE`, `DEFAULT_THEME`, `get_text`, `user_config`, `bot_config`, `welcome_config` are defined).
49
- - `ui_components/logo.py`: Logo component for the GUI.
50
- - `ui_components/settings_header.py`: Settings header component.
51
-
52
- 4. **Run the Application**:
53
-
54
- ```bash
55
- python app.py
56
- ```
57
-
58
- This launches a web interface via Gradio, providing a public URL (e.g., `https://...gradio.live`) if `share=True`.
59
-
60
- ## Usage
61
-
62
- 1. **Launch the Chatbot**:
63
-
64
- - Run `app.py` in a Jupyter notebook, Colab, or terminal.
65
- - Access the web interface through the provided URL.
66
-
67
- 2. **Interact with LogicLink**:
68
-
69
- - **Input Queries**: Type questions or tasks in the input field (e.g., "Tell me about Pakistan" or "Who are you?").
70
- - **Manage Conversations**:
71
- - Click **New Chat** to start a new conversation.
72
- - Click **Clear History** to reset the current conversation.
73
- - Click the **Delete** menu item in the conversation list to remove a conversation.
74
-
75
- 3. **Example Interaction**:
76
-
77
- - **Input**: "Who are you?"
78
- - **Output**:
79
-
80
- ```
81
- I'm LogicLink, Version 5, created by Kratu Gautam, an AIML Engineer. I'm here to help with your questions, so what's up?
82
- *(4.50s)*
83
- ```
84
- - **Input**: "Explain quantum physics briefly"
85
- - **Output**: A concise explanation of quantum physics, followed by `*(X.XXs)*`.
86
-
87
- 4. **Performance**:
88
-
89
- - **Response Time**: \~3–5 seconds per query (faster with CUDA).
90
- - **RAM Usage**: \~2–3 GB on CPU, lower on GPU.
91
-
92
- ## Technical Details
93
-
94
- ### Model Architecture
95
-
96
- - **Base Model**: TinyLlama-1.1B-Chat-v1.0, a lightweight transformer-based language model with 1.1 billion parameters, optimized for chat applications.
97
- - **Framework**: PyTorch with the Transformers library from Hugging Face.
98
- - **Tokenizer**: `AutoTokenizer` configured with left-padding and EOS token handling to ensure proper input formatting for chat sequences.
99
- - **Response Generation**:
100
- - Leverages `AutoModelForCausalLM` for next-token prediction.
101
- - Implements streaming with `TextIteratorStreamer` to output tokens in real-time, enhancing user experience.
102
- - Uses a custom `StopOnTokens` stopping criterion to halt generation at specific tokens (e.g., token ID 2), preventing unnecessary output.
103
- - **Generation Parameters**:
104
- - `max_new_tokens=1024`: Limits response length to 1024 tokens.
105
- - `temperature=0.7`: Balances creativity and coherence in responses.
106
- - `top_k=50`: Considers the top 50 probable tokens for sampling.
107
- - `top_p=0.95`: Applies nucleus sampling to focus on the top 95% probability mass.
108
- - `num_beams=1`: Uses greedy decoding for deterministic output.
109
-
110
- ### Implementation Specifics
111
-
112
- - **Prompt Engineering**:
113
- - The model is instructed via a system prompt:
114
-
115
- ```
116
- You are LogicLink, Version 5, created by Kratu Gautam, an AIML Engineer. Respond to the following user input: {user_input}
117
- ```
118
- - Conversation history is formatted with `<|user|>` and `<|assistant|>` tags, separated by `</s>`, to maintain context.
119
- - **Threading**: Response generation runs in a separate thread using Python’s `Thread` module to prevent blocking the Gradio interface.
120
- - **Time Stamp Handling**:
121
- - A regex (`re.sub(r'\*\(\d+\.\d+s\)\*', '', response)`) removes duplicate time stamps, ensuring each response ends with a single `*(X.XXs)*`.
122
- - **Error Handling**:
123
- - Catches exceptions (e.g., memory errors, model incompatibilities) and appends user-friendly messages to the conversation history.
124
- - Example: `Generation failed: insufficient memory. Possible causes: ...`
125
-
126
- ### GUI
127
-
128
- - **Framework**: Gradio integrated with ModelScope Studio components for a professional-grade interface.
129
- - **Components**:
130
- - `pro.Chatbot`: Renders conversation history with distinct user (blue bubbles) and assistant (dark gray with red borders) messages.
131
- - `antdx.Sender`: Provides an input field with a clear button for user queries.
132
- - `antdx.Conversations`: A sidebar for managing multiple conversations, with a context menu for deletion.
133
- - `antd.Button`: Implements the "New Chat" button and other interactive elements.
134
- - **Styling**: Custom CSS defines a red/blue/black theme:
135
- - User messages: Blue background for visibility.
136
- - Assistant messages: Dark gray with red borders for contrast.
137
- - Buttons: Blue with hover effects for interactivity.
138
- - **Layout**: Uses `antd.Row` and `antd.Col` for responsive design, with a fixed 260px sidebar and flexible chat area.
139
-
140
- ### Performance Optimization
141
-
142
- - **CUDA Support**: Automatically detects CUDA-enabled GPUs via `torch.device('cuda' if torch.cuda.is_available() else 'cpu')`, reducing response times to \~3 seconds on GPU compared to \~5 seconds on CPU.
143
- - **Memory Efficiency**: TinyLlama’s 1.1B parameters require \~2–3 GB RAM on CPU, making it suitable for consumer hardware.
144
- - **Threaded Generation**: Offloads model inference to a separate thread, ensuring the GUI remains responsive during processing.
145
-
146
- ### Key Fixes
147
-
148
- - **Single Time Stamp**: Resolved duplicate time stamps using regex to clean responses before appending `*(X.XXs)*`.
149
- - **Delete Functionality**: Fixed `AntdXConversations` event handling by replacing `select` with `menu_click`, ensuring reliable conversation deletion.
150
- - **Metadata**: Embedded model identity in the prompt to consistently identify as LogicLink V5 by Kratu Gautam.
151
-
152
- ## Troubleshooting
153
-
154
- - **Double Time Stamps**:
155
- - If responses show multiple `*(X.XXs)*`, verify the regex in `logiclink_chat`.
156
- - Test with inputs like "Tell me about Pakistan" and share the output.
157
- - **Slow Responses**:
158
- - Use a CUDA-enabled GPU for faster processing.
159
- - Reduce `max_new_tokens` to 512 if needed.
160
- - Check RAM usage: `!free -h` in Colab.
161
- - **GUI Issues**:
162
- - Ensure `config.py` and `ui_components/` are correctly configured.
163
- - Update dependencies: `pip install --force-reinstall gradio modelscope-studio`.
164
- - **Delete Button Not Working**:
165
- - Verify the `menu_click` event handler and JavaScript snippet.
166
- - Share any error messages or tracebacks.
167
- - **Model Errors**:
168
- - Check for sufficient RAM (\~2–3 GB) and compatible PyTorch/Transformers versions.
169
- - Run a test generation:
170
-
171
- ```python
172
- from transformers import AutoModelForCausalLM, AutoTokenizer
173
- tokenizer = AutoTokenizer.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
174
- model = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0")
175
- inputs = tokenizer(["Hello"], return_tensors="pt")
176
- outputs = model.generate(**inputs, max_new_tokens=10)
177
- print(tokenizer.decode(outputs[0]))
178
- ```
179
-
180
- ## Future Improvements
181
-
182
- - Add a welcome message displaying LogicLink’s identity via `welcome_config()`.
183
- - Enhance prompt engineering for more context-aware responses.
184
- - Implement persistent storage for conversation history using a database or file system.
185
- - Add support for multimodal inputs (e.g., images) to expand functionality.
186
- - Optimize tokenization and generation for lower latency on CPU.
187
-
188
- ## Credits
189
-
190
- - **Developer**: Kratu Gautam, AIML Engineer
191
- - **Dependencies**:
192
- - TinyLlama-1.1B-Chat-v1.0 (Hugging Face)
193
- - Gradio
194
- - PyTorch
195
- - Transformers
196
- - ModelScope Studio
197
- - **Inspiration**: Built to provide an accessible and interactive AI chatbot for students and enthusiasts.
198
-
199
- ## License
200
-
201
- MIT License. See `LICENSE` for details.
202
-
203
  ---
204
-
205
- **LogicLink V5** is a project by Kratu Gautam, showcasing the power of AI in creating intuitive conversational tools. Contributions and feedback are welcome!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: LogicLink Project
3
+ emoji: 🚀
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: gradio
7
+ sdk_version: "3.50.0"
8
+ app_file: app.py
9
+ pinned: false
10
+ ---