underwater45 commited on
Commit
005bde7
1 Parent(s): ad66aa4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -28
app.py CHANGED
@@ -9,46 +9,37 @@ tokenizer = AutoTokenizer.from_pretrained(model_name, token="hf_tjRQQxpOvAuXkssS
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)
@@ -58,8 +49,7 @@ def blackberry_response(prompt):
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
 
@@ -69,8 +59,8 @@ iface = gr.Interface(
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()
 
9
  model = AutoModelForCausalLM.from_pretrained(model_name, token="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")
10
 
11
  # System prompt
12
+ system_prompt = """You are BlackBerry, an advanced AI model with the "Little Thinking" technique. You use four "Berry" thinkers to analyze queries and provide accurate responses."""
13
+
14
+ def generate_response(prompt, max_length=100):
15
+ full_prompt = f"{system_prompt}\n\nUser: {prompt}\n\nBlackBerry:"
16
+ inputs = tokenizer(full_prompt, return_tensors="pt", truncation=True, max_length=512)
17
+ with torch.no_grad():
18
+ outputs = model.generate(**inputs, max_length=max_length, num_return_sequences=1, temperature=0.7)
19
+ response = tokenizer.decode(outputs[0], skip_special_tokens=True)
20
+ return response.split("BlackBerry:")[-1].strip()
21
 
22
  def little_thinking(prompt):
23
  thoughts = []
24
  for i in range(4):
25
+ thought = f"*Berry-{i+1}: {generate_response(f'As Berry-{i+1}, briefly analyze: {prompt}', max_length=50)}*\n\n"
 
 
26
  thoughts.append(thought)
27
  return "".join(thoughts)
28
 
29
  def reviewer_thinking(prompt):
30
+ return f"*Reviewer: {generate_response(f'As a Reviewer, briefly check: {prompt}', max_length=50)}*\n\n"
 
 
 
31
 
32
  def second_reviewer_thinking(prompt):
33
+ return f"*Second Reviewer: {generate_response(f'As a Second Reviewer, briefly verify: {prompt}', max_length=50)}*\n\n"
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  def blackberry_response(prompt):
36
+ response = "BlackBerry: Analyzing with Little Thinking technique.\n\n"
37
 
38
  # Little Thinking process
39
  response += little_thinking(prompt)
40
 
41
+ # Initial answer
42
+ response += f"BlackBerry: Initial answer:\n{generate_response(prompt, max_length=100)}\n\n"
 
43
 
44
  # Reviewer
45
  response += reviewer_thinking(response)
 
49
  response += second_reviewer_thinking(response)
50
 
51
  # Final answer
52
+ response += f"BlackBerry: Final answer:\n{generate_response(prompt, max_length=150)}"
 
53
 
54
  return response
55
 
 
59
  inputs=gr.Textbox(lines=5, label="Enter your query"),
60
  outputs=gr.Textbox(label="BlackBerry's Response"),
61
  title="Blackberry-1 LLM",
62
+ description="Powered by meta-llama/Llama-3.2-1B with 'Little Thinking' technique"
63
  )
64
 
65
  # Launch the app
66
+ iface.launch()