Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import time
|
|
| 6 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 7 |
|
| 8 |
# === CONFIGURATION ===
|
| 9 |
-
MODEL_NAME = "facebook/opt-
|
| 10 |
|
| 11 |
MEMORY_FILE = "memory.json"
|
| 12 |
EMOTIONS_FILE = "emotions.json"
|
|
@@ -76,7 +76,7 @@ def save_state():
|
|
| 76 |
save_json(EMOTIONS_FILE, emotions)
|
| 77 |
save_json(BELIEFS_FILE, beliefs)
|
| 78 |
|
| 79 |
-
def simulate_typing(text, delay=0.
|
| 80 |
typed_text = ""
|
| 81 |
for char in text:
|
| 82 |
typed_text += char
|
|
@@ -94,15 +94,15 @@ def chat_with_ai(user_input, history, turbo_mode):
|
|
| 94 |
conversation += f"User: {msg['user']}\nAssistant thought: {msg['internal_state']}\n"
|
| 95 |
conversation += f"User: {user_input}\nAssistant:"
|
| 96 |
|
| 97 |
-
inputs = tokenizer(conversation, return_tensors="pt", truncation=True, max_length=
|
| 98 |
|
| 99 |
generate_args = {
|
| 100 |
'input_ids': inputs.input_ids,
|
| 101 |
-
'max_length': inputs.input_ids.shape[-1] + (
|
| 102 |
'temperature': 0.6 if turbo_mode else 0.7,
|
| 103 |
-
'top_k':
|
| 104 |
-
'top_p': 0.
|
| 105 |
-
'do_sample':
|
| 106 |
'pad_token_id': tokenizer.eos_token_id,
|
| 107 |
'early_stopping': True
|
| 108 |
}
|
|
@@ -141,17 +141,17 @@ body {
|
|
| 141 |
|
| 142 |
# === GRADIO APP ===
|
| 143 |
with gr.Blocks(css=css) as app:
|
| 144 |
-
gr.Markdown("## π€ Ultra Living AI - OPT
|
| 145 |
|
| 146 |
chatbot = gr.Chatbot(label="Chat History", type="messages", render=False)
|
| 147 |
-
user_input = gr.Textbox(lines=
|
| 148 |
-
ai_output = gr.Textbox(lines=
|
| 149 |
|
| 150 |
with gr.Row():
|
| 151 |
send_btn = gr.Button("Send")
|
| 152 |
clear_btn = gr.Button("Clear Chat")
|
| 153 |
save_btn = gr.Button("Save Chat")
|
| 154 |
-
turbo_mode = gr.Checkbox(label="π Turbo Mode (Faster
|
| 155 |
|
| 156 |
status_box = gr.Textbox(label="System Status", interactive=False)
|
| 157 |
|
|
|
|
| 6 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 7 |
|
| 8 |
# === CONFIGURATION ===
|
| 9 |
+
MODEL_NAME = "facebook/opt-350m" # β
Very fast, perfect for HuggingFace free hardware!
|
| 10 |
|
| 11 |
MEMORY_FILE = "memory.json"
|
| 12 |
EMOTIONS_FILE = "emotions.json"
|
|
|
|
| 76 |
save_json(EMOTIONS_FILE, emotions)
|
| 77 |
save_json(BELIEFS_FILE, beliefs)
|
| 78 |
|
| 79 |
+
def simulate_typing(text, delay=0.005): # Faster simulated typing
|
| 80 |
typed_text = ""
|
| 81 |
for char in text:
|
| 82 |
typed_text += char
|
|
|
|
| 94 |
conversation += f"User: {msg['user']}\nAssistant thought: {msg['internal_state']}\n"
|
| 95 |
conversation += f"User: {user_input}\nAssistant:"
|
| 96 |
|
| 97 |
+
inputs = tokenizer(conversation, return_tensors="pt", truncation=True, max_length=1024).to(model.device)
|
| 98 |
|
| 99 |
generate_args = {
|
| 100 |
'input_ids': inputs.input_ids,
|
| 101 |
+
'max_length': inputs.input_ids.shape[-1] + (30 if turbo_mode else 80), # Shorter outputs
|
| 102 |
'temperature': 0.6 if turbo_mode else 0.7,
|
| 103 |
+
'top_k': 30,
|
| 104 |
+
'top_p': 0.9,
|
| 105 |
+
'do_sample': True,
|
| 106 |
'pad_token_id': tokenizer.eos_token_id,
|
| 107 |
'early_stopping': True
|
| 108 |
}
|
|
|
|
| 141 |
|
| 142 |
# === GRADIO APP ===
|
| 143 |
with gr.Blocks(css=css) as app:
|
| 144 |
+
gr.Markdown("## π€ Ultra Fast Living AI - OPT-350M", elem_id="title")
|
| 145 |
|
| 146 |
chatbot = gr.Chatbot(label="Chat History", type="messages", render=False)
|
| 147 |
+
user_input = gr.Textbox(lines=3, label="Your Message", placeholder="Type your message...")
|
| 148 |
+
ai_output = gr.Textbox(lines=5, label="π€ AI's Response", interactive=False, placeholder="AI will respond here...")
|
| 149 |
|
| 150 |
with gr.Row():
|
| 151 |
send_btn = gr.Button("Send")
|
| 152 |
clear_btn = gr.Button("Clear Chat")
|
| 153 |
save_btn = gr.Button("Save Chat")
|
| 154 |
+
turbo_mode = gr.Checkbox(label="π Turbo Mode (Faster Replies)", value=True)
|
| 155 |
|
| 156 |
status_box = gr.Textbox(label="System Status", interactive=False)
|
| 157 |
|