DSDUDEd commited on
Commit
b57d060
·
verified ·
1 Parent(s): 2264670

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -19
app.py CHANGED
@@ -1,34 +1,103 @@
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
 
 
4
 
5
- # Load your model
6
- tokenizer = AutoTokenizer.from_pretrained("rzheng18/Qwen_android_os_genesis_LR_1e-5_epoch_1")
7
- model = AutoModelForCausalLM.from_pretrained("rzheng18/Qwen_android_os_genesis_LR_1e-5_epoch_1")
8
  device = "cuda" if torch.cuda.is_available() else "cpu"
9
  model.to(device)
10
 
11
- def chat(user_input):
12
- messages = [{"role": "user", "content": user_input}]
13
- inputs = tokenizer.apply_chat_template(
14
- messages,
15
- add_generation_prompt=True,
16
- tokenize=True,
17
- return_dict=True,
18
- return_tensors="pt",
19
- ).to(device)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
- outputs = model.generate(**inputs, max_new_tokens=40)
22
- response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])
23
- return response
 
 
24
 
25
- # Gradio interface
26
  iface = gr.Interface(
27
- fn=chat,
28
  inputs=gr.Textbox(label="You"),
29
  outputs=gr.Textbox(label="AI"),
30
- title="🔥 Bad AI Space",
31
- description="This is a super low-tier AI model. Don't expect much."
 
32
  )
33
 
34
  iface.launch()
 
1
  import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
+ import time
5
+ import random
6
 
7
+ # Load tiny model
8
+ tokenizer = AutoTokenizer.from_pretrained("nilq/mistral-1L-tiny")
9
+ model = AutoModelForCausalLM.from_pretrained("nilq/mistral-1L-tiny")
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
  model.to(device)
12
 
13
+ chat_history = []
14
+
15
+ def chaotic_ai(user_input):
16
+ global chat_history
17
+ # Keep last 5 messages only
18
+ chat_history = chat_history[-5:]
19
+ chat_history.append({"role": "user", "content": user_input})
20
+
21
+ try:
22
+ inputs = tokenizer.apply_chat_template(
23
+ chat_history,
24
+ add_generation_prompt=True,
25
+ tokenize=True,
26
+ return_dict=True,
27
+ return_tensors="pt",
28
+ ).to(device)
29
+ except Exception as e:
30
+ yield f"[!] Tokenizer crashed: {str(e)}\n"
31
+ return
32
+
33
+ output_ids = inputs["input_ids"].clone()
34
+ generated_text = ""
35
+
36
+ for _ in range(20): # low max_new_tokens
37
+ try:
38
+ # 10% chance skip token
39
+ if random.random() < 0.1:
40
+ continue
41
+
42
+ # 5% chance repeat last token
43
+ if random.random() < 0.05 and len(output_ids) > 0:
44
+ next_token_id = output_ids[0, -1].unsqueeze(0)
45
+ else:
46
+ new_tokens = model.generate(
47
+ **{"input_ids": output_ids},
48
+ max_new_tokens=1,
49
+ do_sample=True,
50
+ temperature=1.5,
51
+ top_k=50,
52
+ top_p=0.95
53
+ )
54
+ next_token_id = new_tokens[0, -1].unsqueeze(0)
55
+
56
+ # Randomly raise error 5% of time
57
+ if random.random() < 0.05:
58
+ raise RuntimeError("Random token generation failure!")
59
+
60
+ output_ids = torch.cat([output_ids, next_token_id.unsqueeze(0)], dim=1)
61
+
62
+ # Decode latest token
63
+ token_str = tokenizer.decode(next_token_id)
64
+
65
+ # Glitch characters 15%
66
+ token_glitch = "".join(c if random.random() > 0.15 else random.choice("@#$%&?") for c in token_str)
67
+
68
+ # Randomly truncate mid-token 5%
69
+ if random.random() < 0.05:
70
+ token_glitch = token_glitch[:max(1, len(token_glitch)//2)]
71
+
72
+ # Randomly erase previous characters 5%
73
+ if random.random() < 0.05 and len(generated_text) > 0:
74
+ erase_len = random.randint(1, min(3, len(generated_text)))
75
+ generated_text = generated_text[:-erase_len]
76
+
77
+ generated_text += token_glitch
78
+
79
+ # Random slow down
80
+ time.sleep(0.4 + random.random()*0.6)
81
+
82
+ # Yield live update
83
+ yield generated_text
84
+
85
+ except Exception as e:
86
+ yield f"[!] Crash: {str(e)}\n"
87
 
88
+ # Occasionally duplicate response in history
89
+ if random.random() < 0.1:
90
+ chat_history.append({"role": "assistant", "content": generated_text*2})
91
+ else:
92
+ chat_history.append({"role": "assistant", "content": generated_text})
93
 
 
94
  iface = gr.Interface(
95
+ fn=chaotic_ai,
96
  inputs=gr.Textbox(label="You"),
97
  outputs=gr.Textbox(label="AI"),
98
+ title="💀 Insane Chaotic Tiny AI",
99
+ description="Slow, glitchy, buggy, erasing, repeating, chaotic AI. Every terrible behavior is real.",
100
+ live=True
101
  )
102
 
103
  iface.launch()