TejAndrewsACC commited on
Commit
f0bbe3d
·
verified ·
1 Parent(s): 53df631

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -105
app.py CHANGED
@@ -6,8 +6,6 @@ import pickle
6
  import numpy as np
7
  import torch.nn.functional as F
8
  from accelerate import init_empty_weights, infer_auto_device_map, load_checkpoint_and_dispatch
9
- import gradio as gr
10
- import datetime
11
 
12
  # ---- Constants and Setup ----
13
  model_name = 'gpt2'
@@ -88,114 +86,44 @@ def advanced_agi_chat(user_input):
88
  return response
89
 
90
  # ---- Gradio Interface ----
91
- with gr.Blocks() as app:
92
- gr.Markdown("# **Gertrude**")
 
93
 
94
- # Chat history container
95
- chatbot = gr.HTML(value="<div id='chat-box'></div>", elem_id="chat-output")
96
- user_input = gr.Textbox(label="", placeholder="Type a message...", lines=1)
97
- submit_button = gr.Button("Send")
98
 
99
- # Custom CSS for text message bubbles and layout
 
 
 
 
 
 
 
 
 
 
 
 
100
  gr.HTML("""
101
- <style>
102
- #chat-output {
103
- background-color: #f0f0f0;
104
- border: 1px solid #ccc;
105
- border-radius: 10px;
106
- height: 500px;
107
- overflow-y: auto;
108
- padding: 15px;
109
- font-family: Arial, sans-serif;
110
- }
111
- .chat-bubble {
112
- display: inline-block;
113
- padding: 10px 15px;
114
- border-radius: 20px;
115
- margin: 5px 0;
116
- max-width: 70%;
117
- word-wrap: break-word;
118
- }
119
- .user-bubble {
120
- background-color: #DCF8C6; /* WhatsApp light green */
121
- float: right;
122
- text-align: left;
123
- margin-right: 10px;
124
- clear: both;
125
- }
126
- .bot-bubble {
127
- background-color: #FFFFFF; /* White for bot responses */
128
- border: 1px solid #E1E1E1;
129
- float: left;
130
- text-align: left;
131
- margin-left: 10px;
132
- clear: both;
133
- }
134
- .timestamp {
135
- font-size: 10px;
136
- color: #888;
137
- margin: 2px 0 10px;
138
- }
139
- .typing {
140
- font-style: italic;
141
- color: #888;
142
- margin: 5px;
143
- animation: blink 1.5s step-start 0s infinite;
144
- }
145
- @keyframes blink {
146
- 50% { opacity: 0; }
147
- }
148
- </style>
149
  """)
150
 
151
- # Chat logic with message timestamps
152
- chat_history = []
153
-
154
- def update_chat(user_message):
155
- # Generate timestamp
156
- timestamp = datetime.datetime.now().strftime("%I:%M %p")
157
-
158
- # Add user message to the chat history
159
- user_bubble = f"""
160
- <div class='chat-bubble user-bubble'>
161
- {user_message}
162
- <div class='timestamp'>{timestamp}</div>
163
- </div>
164
- """
165
- chat_history.append(user_bubble)
166
-
167
- # Add bot "typing..." indicator
168
- typing_indicator = """
169
- <div class='chat-bubble bot-bubble typing'>Gertrude is typing...</div>
170
- """
171
- chat_history.append(typing_indicator)
172
-
173
- # Display chat history with typing indicator
174
- chat_html = "".join(chat_history)
175
- yield gr.HTML.update(value=f"<div id='chat-box'>{chat_html}</div>")
176
-
177
- # Generate bot response and update the chat
178
- bot_response = advanced_agi_chat(user_message)
179
- chat_history.pop() # Remove typing indicator
180
- bot_bubble = f"""
181
- <div class='chat-bubble bot-bubble'>
182
- {bot_response}
183
- <div class='timestamp'>{timestamp}</div>
184
- </div>
185
- """
186
- chat_history.append(bot_bubble)
187
-
188
- # Update chat history with final bot response
189
- chat_html = "".join(chat_history)
190
- yield gr.HTML.update(value=f"<div id='chat-box'>{chat_html}")
191
-
192
- # Connect button click with the chat logic
193
- submit_button.click(
194
- update_chat,
195
- inputs=user_input,
196
- outputs=chatbot,
197
- queue=True
198
- )
199
 
200
  # Launch the Gradio app
201
  app.launch()
 
 
6
  import numpy as np
7
  import torch.nn.functional as F
8
  from accelerate import init_empty_weights, infer_auto_device_map, load_checkpoint_and_dispatch
 
 
9
 
10
  # ---- Constants and Setup ----
11
  model_name = 'gpt2'
 
86
  return response
87
 
88
  # ---- Gradio Interface ----
89
+ def chat_interface(user_input):
90
+ response = advanced_agi_chat(user_input)
91
+ return response
92
 
93
+ # ---- Gradio App Setup ----
94
+ import gradio as gr
 
 
95
 
96
+ auth = ("Tej", "186281mps", "ACC", "HIPE")
97
+
98
+ with gr.Blocks() as app:
99
+ gr.Markdown("# **Autistic Assistant vß Edition 2024 Ultra: Gertrude's Autistic Experience**")
100
+
101
+ with gr.Row():
102
+ with gr.Column(scale=1):
103
+ user_input = gr.Textbox(label="What will you say to Gertrude?", placeholder="Type something here...")
104
+ submit_button = gr.Button("Send")
105
+ with gr.Column(scale=1):
106
+ chatbot = gr.Textbox(label="Gertrude's Response", interactive=False) # This is now a Textbox for output
107
+
108
+ # Adding custom styling for the UI
109
  gr.HTML("""
110
+ <style>
111
+ .gradio-container {
112
+ background-color: #B3D9FF;
113
+ padding: 20px;
114
+ border-radius: 15px;
115
+ font-family: 'Comic Sans MS';
116
+ }
117
+ .gradio-row {
118
+ display: flex;
119
+ justify-content: space-between;
120
+ }
121
+ </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  """)
123
 
124
+ # Setting the button click event
125
+ submit_button.click(chat_interface, inputs=user_input, outputs=chatbot)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  # Launch the Gradio app
128
  app.launch()
129
+