Dawn-AI commited on
Commit
d324449
·
verified ·
1 Parent(s): d1825a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -10
app.py CHANGED
@@ -2,39 +2,58 @@ import gradio as gr
2
  import torch
3
  from transformers import pipeline
4
 
5
- print("Loading Dawn-superlite")
6
- # We add model_kwargs to silence the "tie_word_embeddings" warnings
 
 
7
  pipe = pipeline(
8
  "text-generation",
9
- model="Dawn-AI/Dawn-superlite", # Make sure this is your actual repo name
10
  device_map="auto",
11
- torch_dtype=torch.bfloat16, # Use bfloat16 to save some memory if possible
 
12
  model_kwargs={
13
  "tie_word_embeddings": False
14
  }
15
  )
 
16
  print("Model loaded successfully!")
17
 
18
  def chat_with_dawn(message, history, system_prompt):
19
  messages = []
20
 
 
21
  if system_prompt.strip():
22
  messages.append({"role": "system", "content": system_prompt})
23
 
 
24
  for user_msg, assistant_msg in history:
25
  messages.append({"role": "user", "content": user_msg})
26
  messages.append({"role": "assistant", "content": assistant_msg})
27
 
 
28
  messages.append({"role": "user", "content": message})
29
 
30
- response = pipe(messages, max_new_tokens=512, truncation=True)
 
 
 
 
 
 
 
 
 
 
 
31
  generated_text = response[0]['generated_text']
32
 
 
33
  if isinstance(generated_text, list):
34
  return generated_text[-1]['content']
35
- else:
36
- return generated_text
37
 
 
38
  system_textbox = gr.Textbox(
39
  value="You are Dawn, a brilliant reasoning AI.",
40
  label="System Prompt",
@@ -42,13 +61,13 @@ system_textbox = gr.Textbox(
42
  interactive=True
43
  )
44
 
45
- # NOTICE: The theme="soft" line has been removed to prevent the crash!
46
  demo = gr.ChatInterface(
47
  fn=chat_with_dawn,
48
  additional_inputs=[system_textbox],
49
  title="🌅 Dawn Superlite",
50
- description="Running Dawn. Warning: May be slow on CPU.",
51
- examples=["Who are you?", "Write a Python script to reverse a string."]
52
  )
53
 
54
  if __name__ == "__main__":
 
2
  import torch
3
  from transformers import pipeline
4
 
5
+ print("Loading Dawn-superlite...")
6
+
7
+ # The 'trust_remote_code=True' argument is required for this specific model
8
+ # because it uses a custom architecture defined in the HF repository.
9
  pipe = pipeline(
10
  "text-generation",
11
+ model="Dawn-AI/Dawn-superlite",
12
  device_map="auto",
13
+ torch_dtype=torch.bfloat16,
14
+ trust_remote_code=True,
15
  model_kwargs={
16
  "tie_word_embeddings": False
17
  }
18
  )
19
+
20
  print("Model loaded successfully!")
21
 
22
  def chat_with_dawn(message, history, system_prompt):
23
  messages = []
24
 
25
+ # Add system prompt if provided
26
  if system_prompt.strip():
27
  messages.append({"role": "system", "content": system_prompt})
28
 
29
+ # Build history for the chat template
30
  for user_msg, assistant_msg in history:
31
  messages.append({"role": "user", "content": user_msg})
32
  messages.append({"role": "assistant", "content": assistant_msg})
33
 
34
+ # Append the new user message
35
  messages.append({"role": "user", "content": message})
36
 
37
+ # Generate response
38
+ # Using a temperature > 0 and top_p for more natural reasoning responses
39
+ response = pipe(
40
+ messages,
41
+ max_new_tokens=512,
42
+ truncation=True,
43
+ do_sample=True,
44
+ temperature=0.7,
45
+ top_p=0.9
46
+ )
47
+
48
+ # Extract the text from the returned message object
49
  generated_text = response[0]['generated_text']
50
 
51
+ # The pipeline usually returns the full list of messages including the new one
52
  if isinstance(generated_text, list):
53
  return generated_text[-1]['content']
54
+ return str(generated_text)
 
55
 
56
+ # Define the UI components
57
  system_textbox = gr.Textbox(
58
  value="You are Dawn, a brilliant reasoning AI.",
59
  label="System Prompt",
 
61
  interactive=True
62
  )
63
 
64
+ # Launch the Gradio Interface
65
  demo = gr.ChatInterface(
66
  fn=chat_with_dawn,
67
  additional_inputs=[system_textbox],
68
  title="🌅 Dawn Superlite",
69
+ description="Running Dawn-superlite. Note: Performance depends on your hardware (CPU vs GPU).",
70
+ examples=["Explain quantum entanglement like I'm five.", "Write a Python script to reverse a string."]
71
  )
72
 
73
  if __name__ == "__main__":