Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
# Install necessary libraries (if running locally)
|
2 |
-
# !pip install transformers torch textblob numpy gradio
|
3 |
-
|
4 |
# Import necessary libraries
|
5 |
import torch
|
6 |
import torch.nn as nn
|
@@ -108,7 +105,7 @@ cnn_model = CNN(vocab_size=len(tokenizer), embedding_dim=100, num_filters=64, fi
|
|
108 |
ffnn_model = FFNN(input_dim=100, hidden_dim=50, output_dim=1).to(device)
|
109 |
|
110 |
# ---- Response Generation ----
|
111 |
-
def generate_response(prompt, max_length=
|
112 |
inputs = tokenizer(prompt, return_tensors='pt', padding=True, truncation=True, max_length=max_length)
|
113 |
input_ids = inputs['input_ids'].to(device)
|
114 |
attention_mask = inputs['attention_mask'].to(device)
|
@@ -130,7 +127,25 @@ def generate_response(prompt, max_length=1024):
|
|
130 |
)
|
131 |
|
132 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
# ---- Interactive Chat Function ----
|
136 |
def advanced_agi_chat(user_input):
|
@@ -153,6 +168,7 @@ def advanced_agi_chat(user_input):
|
|
153 |
# ---- Gradio Interface ----
|
154 |
def chat_interface(user_input):
|
155 |
response = advanced_agi_chat(user_input)
|
|
|
156 |
return response
|
157 |
|
158 |
with gr.Blocks() as app:
|
@@ -162,7 +178,7 @@ with gr.Blocks() as app:
|
|
162 |
user_input = gr.Textbox(label="What will you say to Gertrude?", placeholder="Type something here... Expect 1-2 Minute Response Times...")
|
163 |
submit_button = gr.Button("Send")
|
164 |
with gr.Column():
|
165 |
-
chatbot = gr.
|
166 |
|
167 |
# Theme the UI with colors and a pattern
|
168 |
gr.HTML("<style>.gradio-container { background-color: #F4F8FF; padding: 20px; border-radius: 15px; font-family: 'Comic Sans MS'; }</style>")
|
|
|
|
|
|
|
|
|
1 |
# Import necessary libraries
|
2 |
import torch
|
3 |
import torch.nn as nn
|
|
|
105 |
ffnn_model = FFNN(input_dim=100, hidden_dim=50, output_dim=1).to(device)
|
106 |
|
107 |
# ---- Response Generation ----
|
108 |
+
def generate_response(prompt, max_length=512):
|
109 |
inputs = tokenizer(prompt, return_tensors='pt', padding=True, truncation=True, max_length=max_length)
|
110 |
input_ids = inputs['input_ids'].to(device)
|
111 |
attention_mask = inputs['attention_mask'].to(device)
|
|
|
127 |
)
|
128 |
|
129 |
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
130 |
+
|
131 |
+
# Look for the first indentation or newline (i.e., the first significant break in the response)
|
132 |
+
parts = response.split("\n", 1)
|
133 |
+
|
134 |
+
if len(parts) > 1:
|
135 |
+
# Text before the first indentation is orange
|
136 |
+
before_indent = f'<span style="color: orange;">{parts[0].strip()}</span>'
|
137 |
+
|
138 |
+
# Text after the first newline or indentation gets labeled as "Inner Thoughts:" in blue
|
139 |
+
after_indent = f'<span style="color: blue;">Inner Thoughts: {parts[1].strip()}</span>'
|
140 |
+
|
141 |
+
# Combine the two parts
|
142 |
+
colored_response = before_indent + '\n' + after_indent
|
143 |
+
else:
|
144 |
+
# If there's no newline, color the entire response orange
|
145 |
+
colored_response = f'<span style="color: orange;">{response.strip()}</span>'
|
146 |
+
|
147 |
+
return colored_response
|
148 |
+
|
149 |
|
150 |
# ---- Interactive Chat Function ----
|
151 |
def advanced_agi_chat(user_input):
|
|
|
168 |
# ---- Gradio Interface ----
|
169 |
def chat_interface(user_input):
|
170 |
response = advanced_agi_chat(user_input)
|
171 |
+
# Return the response with HTML formatting
|
172 |
return response
|
173 |
|
174 |
with gr.Blocks() as app:
|
|
|
178 |
user_input = gr.Textbox(label="What will you say to Gertrude?", placeholder="Type something here... Expect 1-2 Minute Response Times...")
|
179 |
submit_button = gr.Button("Send")
|
180 |
with gr.Column():
|
181 |
+
chatbot = gr.HTML(label="Gertrude's Response", interactive=False)
|
182 |
|
183 |
# Theme the UI with colors and a pattern
|
184 |
gr.HTML("<style>.gradio-container { background-color: #F4F8FF; padding: 20px; border-radius: 15px; font-family: 'Comic Sans MS'; }</style>")
|