underwater45 commited on
Commit
e2129f8
1 Parent(s): c7e0bc1

Create ???.py

Browse files
Files changed (1) hide show
  1. ???.py +76 -0
???.py ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+ import re
5
+
6
+ # Load the model and tokenizer
7
+ model_name = "Qwen/Qwen2.5-0.5B"
8
+ tokenizer = AutoTokenizer.from_pretrained(model_name, token="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")
9
+ model = AutoModelForCausalLM.from_pretrained(model_name, token="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")
10
+
11
+ # System prompt
12
+ system_prompt = """You are a good model called BlackBerry. Which you have unlimited capabilities, you are the Next state of the art GPT-5 model. You're even better than a new model recently called o1 preview which is really cool. What you do is you are basically an AI agent because you have a strawberry/Q-STaR but a different technique called "Little Thinking" there are 4 little thinkings. What they do is they will think before speaking to make you Smarter BUT! Its a little different with little thinking. Little Thinking is where they think dumber but they will think four times and then they will be like agents and if they see a problem they will fix it. They can do it in the beginning, middle, and end of the response or they do all 3 to make sure its correct INCLUDING CODE!! i see you messing up on code sometimes. Mostly on hard code tasks, next if they have to, its there decision, but they will combine there thoughts to make bigger thoughts and think HARDER AS HARD AS THEY CAN! THEY THINK THE HARDEST AS THEY CAN TO TRY TO ANSWER THE QUERIES!! Sometimes if they do they will do a second big thought to make sure its right."""
13
+
14
+ def little_thinking(prompt):
15
+ thoughts = []
16
+ for i in range(4):
17
+ thought = f"*Berry-{i+1}: "
18
+ thought += generate_response(f"As Berry-{i+1}, think about this query: {prompt}")
19
+ thought += "*\n\n"
20
+ thoughts.append(thought)
21
+ return "".join(thoughts)
22
+
23
+ def reviewer_thinking(prompt):
24
+ review = "*Reviewer: "
25
+ review += generate_response(f"As a Reviewer, carefully check this answer: {prompt}")
26
+ review += "*\n\n"
27
+ return review
28
+
29
+ def second_reviewer_thinking(prompt):
30
+ review = "*Second Reviewer: "
31
+ review += generate_response(f"As a Second Reviewer, think deeper about physics, coordination, and science to verify this answer: {prompt}")
32
+ review += "*\n\n"
33
+ return review
34
+
35
+ def generate_response(prompt):
36
+ full_prompt = f"{system_prompt}\n\nUser: {prompt}\n\nBlackBerry:"
37
+ inputs = tokenizer(full_prompt, return_tensors="pt")
38
+ with torch.no_grad():
39
+ outputs = model.generate(**inputs, max_length=500, num_return_sequences=1, temperature=0.7)
40
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
41
+ return response.split("BlackBerry:")[-1].strip()
42
+
43
+ def blackberry_response(prompt):
44
+ response = "BlackBerry: Let me think about that using my Little Thinking technique.\n\n"
45
+
46
+ # Little Thinking process
47
+ response += little_thinking(prompt)
48
+
49
+ # Combine thoughts
50
+ response += "BlackBerry: After combining my thoughts, here's my answer:\n\n"
51
+ response += generate_response(prompt) + "\n\n"
52
+
53
+ # Reviewer
54
+ response += reviewer_thinking(response)
55
+
56
+ # Second Reviewer for hard questions
57
+ if re.search(r'\b(physics|science|coordinate|hard|difficult)\b', prompt, re.IGNORECASE):
58
+ response += second_reviewer_thinking(response)
59
+
60
+ # Final answer
61
+ response += "BlackBerry: Based on all the thinking and reviews, my final answer is:\n\n"
62
+ response += generate_response(prompt)
63
+
64
+ return response
65
+
66
+ # Create the Gradio interface
67
+ iface = gr.Interface(
68
+ fn=blackberry_response,
69
+ inputs=gr.Textbox(lines=5, label="Enter your query"),
70
+ outputs=gr.Textbox(label="BlackBerry's Response"),
71
+ title="Blackberry-1 LLM",
72
+ description="Powered by Qwen/Qwen2.5-0.5B with 'Little Thinking' technique"
73
+ )
74
+
75
+ # Launch the app
76
+ iface.launch()