| | import gradio as gr |
| | import torch |
| | from transformers import pipeline |
| |
|
| | print("Loading Dawn-superlite...") |
| |
|
| | |
| | |
| | pipe = pipeline( |
| | "text-generation", |
| | model="Dawn-AI/Dawn-Superlite-llama", |
| | device_map="auto", |
| | torch_dtype=torch.bfloat16, |
| | trust_remote_code=True, |
| | model_kwargs={ |
| | "tie_word_embeddings": False |
| | } |
| | ) |
| |
|
| | print("Model loaded successfully!") |
| |
|
| | def chat_with_dawn(message, history, system_prompt): |
| | messages = [] |
| | |
| | |
| | if system_prompt.strip(): |
| | messages.append({"role": "system", "content": system_prompt}) |
| | |
| | |
| | for user_msg, assistant_msg in history: |
| | messages.append({"role": "user", "content": user_msg}) |
| | messages.append({"role": "assistant", "content": assistant_msg}) |
| | |
| | |
| | messages.append({"role": "user", "content": message}) |
| | |
| | |
| | |
| | response = pipe( |
| | messages, |
| | max_new_tokens=512, |
| | truncation=True, |
| | do_sample=True, |
| | temperature=0.7, |
| | top_p=0.9 |
| | ) |
| | |
| | |
| | generated_text = response[0]['generated_text'] |
| | |
| | |
| | if isinstance(generated_text, list): |
| | return generated_text[-1]['content'] |
| | return str(generated_text) |
| |
|
| | |
| | system_textbox = gr.Textbox( |
| | value="You are Dawn, a brilliant reasoning AI.", |
| | label="System Prompt", |
| | lines=2, |
| | interactive=True |
| | ) |
| |
|
| | |
| | demo = gr.ChatInterface( |
| | fn=chat_with_dawn, |
| | additional_inputs=[system_textbox], |
| | title="🌅 Dawn Superlite", |
| | description="Running Dawn-superlite. Note: Performance depends on your hardware (CPU vs GPU).", |
| | examples=["Explain quantum entanglement like I'm five.", "Write a Python script to reverse a string."] |
| | ) |
| |
|
| | if __name__ == "__main__": |
| | demo.launch() |