Spaces:
Paused
Paused
Create core.py
Browse files
core.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
from transformers import pipeline, set_seed
|
| 5 |
+
|
| 6 |
+
# Initialize Hugging Face text generation pipeline
|
| 7 |
+
generator = pipeline("text-generation", model="flux-dev") # You can swap this with another HF model
|
| 8 |
+
set_seed(42)
|
| 9 |
+
|
| 10 |
+
# Simulate typing output
|
| 11 |
+
def type_out(text, speed=0.02):
|
| 12 |
+
for char in text:
|
| 13 |
+
sys.stdout.write(char)
|
| 14 |
+
sys.stdout.flush()
|
| 15 |
+
time.sleep(speed)
|
| 16 |
+
print()
|
| 17 |
+
|
| 18 |
+
# Clear terminal screen
|
| 19 |
+
def clear_screen():
|
| 20 |
+
os.system('cls' if os.name == 'nt' else 'clear')
|
| 21 |
+
|
| 22 |
+
# Generate AI response using HF pipeline
|
| 23 |
+
def codette_generate(prompt: str) -> str:
|
| 24 |
+
output = generator(prompt, max_length=100, num_return_sequences=1)
|
| 25 |
+
return output[0]['generated_text']
|
| 26 |
+
|
| 27 |
+
# Launch the terminal interface
|
| 28 |
+
def launch_codette_terminal():
|
| 29 |
+
clear_screen()
|
| 30 |
+
type_out("🧬 Welcome to Codette Terminal (Hugging Face Edition) 🧬", 0.03)
|
| 31 |
+
type_out("Ask anything. Type 'exit' to quit.\n", 0.02)
|
| 32 |
+
|
| 33 |
+
while True:
|
| 34 |
+
try:
|
| 35 |
+
user_input = input("🖋️ You > ").strip()
|
| 36 |
+
if user_input.lower() in ['exit', 'quit']:
|
| 37 |
+
type_out("\n🧠 Codette signing off... Stay recursive 🌀\n", 0.04)
|
| 38 |
+
break
|
| 39 |
+
elif not user_input:
|
| 40 |
+
continue
|
| 41 |
+
type_out("💭 Thinking...", 0.04)
|
| 42 |
+
time.sleep(1)
|
| 43 |
+
response = codette_generate(user_input)
|
| 44 |
+
type_out(response.strip(), 0.01)
|
| 45 |
+
except KeyboardInterrupt:
|
| 46 |
+
print("\n[Interrupted] Use 'exit' to quit.\n")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
type_out(f"[Error] {e}", 0.01)
|
| 49 |
+
|
| 50 |
+
if __name__ == "__main__":
|
| 51 |
+
launch_codette_terminal()
|