Tonic commited on
Commit
55a28df
·
unverified ·
1 Parent(s): 0aad095

initial commit

Browse files
Files changed (2) hide show
  1. app.py +73 -0
  2. requirements.txt +0 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import transformers
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
5
+ import torch
6
+
7
+ title = """
8
+ # Welcome to 🌟Tonic's🫡Command-A
9
+ 🫡Command-A is a Large Language Model optimized for conversational interaction and long context tasks. It targets the “scalable” category of models that balance high performance with strong accuracy, enabling companies to move beyond proof of concept, and into production. 🫡Command-A boasts high precision on retrieval augmented generation (RAG) and tool use tasks, low latency and high throughput, a long 128k context, and strong capabilities across 10 key languages. You can build with this endpoint using🫡Command-R available here : [CohereForAI/c4ai-command-r-v01](https://huggingface.co/CohereForAI/c4ai-command-r-v01). You can also use 🫡Command-A by cloning this space. Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic/Command-A?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></h3>
10
+ Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's 🛠️community 👻 [![Join us on Discord](https://img.shields.io/discord/1109943800132010065?label=Discord&logo=discord&style=flat-square)](https://discord.gg/GWpVpekp) On 🤗Huggingface:[MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to🌟 [DataTonic](https://huggingface.co/DataTonic)🤗Big thanks to Yuvi Sharma and all the folks at huggingface for the community grant 🤗
11
+ """
12
+
13
+ model_id = "Tonic/c4ai-command-a-03-2025-4bit_fp4"
14
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
15
+ model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", torch_dtype=torch.bfloat16)
16
+
17
+
18
+ @spaces.GPU
19
+ def generate_response(user_input, max_new_tokens, temperature):
20
+ messages = [{"role": "user", "content": user_input}]
21
+ input_ids = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
22
+ input_ids = input_ids.to(model.device)
23
+ gen_tokens = model.generate(
24
+ input_ids = input_ids,
25
+ max_new_tokens=max_new_tokens,
26
+ do_sample=True,
27
+ temperature=temperature,
28
+ )
29
+
30
+ gen_text = tokenizer.decode(gen_tokens[0], skip_special_tokens=True)
31
+ if gen_text.startswith(user_input):
32
+ gen_text = gen_text[len(user_input):].lstrip()
33
+
34
+ return gen_text
35
+
36
+
37
+
38
+ examples = [
39
+ {"message": "What is the weather like today?", "max_new_tokens": 250, "temperature": 0.5},
40
+ {"message": "Tell me a joke.", "max_new_tokens": 650, "temperature": 0.7},
41
+ {"message": "Explain the concept of machine learning.", "max_new_tokens": 980, "temperature": 0.4}
42
+ ]
43
+ example_choices = [f"Example {i+1}" for i in range(len(examples))]
44
+
45
+ def load_example(choice):
46
+ index = example_choices.index(choice)
47
+ example = examples[index]
48
+ return example["message"], example["max_new_tokens"], example["temperature"]
49
+
50
+
51
+ with gr.Blocks() as demo:
52
+ gr.Markdown(title)
53
+ with gr.Row():
54
+ max_new_tokens_slider = gr.Slider(minimum=100, maximum=4000, value=980, label="Max New Tokens")
55
+ temperature_slider = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.3, label="Temperature")
56
+ message_box = gr.Textbox(lines=2, label="Your Message")
57
+ generate_button = gr.Button("Try🫡Command-A")
58
+ output_box = gr.Textbox(label="🫡Command-A")
59
+
60
+ generate_button.click(
61
+ fn=generate_response,
62
+ inputs=[message_box, max_new_tokens_slider, temperature_slider],
63
+ outputs=output_box
64
+ )
65
+ example_dropdown = gr.Dropdown(label="🫡Load Example", choices=example_choices)
66
+ example_button = gr.Button("🫡Load")
67
+ example_button.click(
68
+ fn=load_example,
69
+ inputs=example_dropdown,
70
+ outputs=[message_box, max_new_tokens_slider, temperature_slider]
71
+ )
72
+
73
+ demo.launch(ssr_mode=False)
requirements.txt ADDED
File without changes