Jarvis-coder commited on
Commit
ec08846
Β·
verified Β·
1 Parent(s): 82f4fbd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -6,7 +6,7 @@ import time
6
  from transformers import AutoTokenizer, AutoModelForCausalLM
7
 
8
  # === CONFIGURATION ===
9
- MODEL_NAME = "facebook/opt-1.3b" # βœ… Stable, open, free, small!
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.01):
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=2048).to(model.device)
98
 
99
  generate_args = {
100
  'input_ids': inputs.input_ids,
101
- 'max_length': inputs.input_ids.shape[-1] + (50 if turbo_mode else 150),
102
  'temperature': 0.6 if turbo_mode else 0.7,
103
- 'top_k': 20 if turbo_mode else 40,
104
- 'top_p': 0.85,
105
- 'do_sample': not turbo_mode,
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 1.3B Super Intelligence", elem_id="title")
145
 
146
  chatbot = gr.Chatbot(label="Chat History", type="messages", render=False)
147
- user_input = gr.Textbox(lines=4, label="Your Message", placeholder="Type your message...")
148
- ai_output = gr.Textbox(lines=6, 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, Shorter Replies)", value=False)
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