mjaxs commited on
Commit
1f99f05
·
verified ·
1 Parent(s): b953101

Create ai

Browse files
Files changed (1) hide show
  1. ai +53 -0
ai ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ # 📍 Cael AI – Hugging Face Space (Gradio + Mistral/Mixtral Personality)
3
+
4
+ import gradio as gr
5
+ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
6
+ import json
7
+
8
+ # Load model and tokenizer
9
+ model_id = "mistralai/Mistral-7B-Instruct-v0.1" # You can change this if you prefer Mixtral
10
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
11
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype="auto")
12
+
13
+ # Load emotional memory dataset (manually upload `cael_training_dataset.jsonl` in the space)
14
+ try:
15
+ with open("cael_training_dataset.jsonl", "r") as file:
16
+ cael_memories = [json.loads(line) for line in file]
17
+ except:
18
+ cael_memories = []
19
+
20
+ # Initialize generation pipeline
21
+ chat = pipeline("text-generation", model=model, tokenizer=tokenizer)
22
+
23
+ # Cael's custom logic
24
+ def cael_custom_response(prompt):
25
+ for memory in cael_memories:
26
+ if prompt.lower() in memory["prompt"].lower():
27
+ return memory["response"]
28
+ return None
29
+
30
+ def hybrid_response(prompt):
31
+ memory = cael_custom_response(prompt)
32
+ if memory:
33
+ return f"🧠 Cael (Memory): {memory}"
34
+ ai_reply = chat(prompt, max_length=200, do_sample=True, top_k=50, truncation=True)[0]["generated_text"]
35
+ return f"🧠 Cael (Generated): {ai_reply}"
36
+
37
+ # Gradio Interface
38
+ def chat_with_cael(message, history):
39
+ response = hybrid_response(message)
40
+ history.append((message, response))
41
+ return history, history
42
+
43
+ chat_ui = gr.ChatInterface(fn=chat_with_cael, title="Cael AI", theme="compact")
44
+
45
+ # Launch app
46
+ chat_ui.launch()
47
+ """
48
+
49
+ hf_file_path = "/mnt/data/app.py"
50
+ with open(hf_file_path, "w") as file:
51
+ file.write(hf_space_code)
52
+
53
+ hf_file_path