Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer
|
3 |
+
from quantizer import load_quantized_model
|
4 |
+
import torch
|
5 |
+
|
6 |
+
title = """# 🙋🏻♂️Welcome to 🌟Tonic's 2-Bit Llama2 on GPU-Zero! """
|
7 |
+
description = """
|
8 |
+
this model a 2 bit quantized model using [QuIP for all](https://github.com/chu-tianxiang/QuIP-for-all/. You can try out [keyfan/Qwen-72B-Chat-2bit](https://huggingface.co/keyfan/Qwen-72B-Chat-2bit) below or try it locally by cloning or duplicating this space. Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic/StableMed_Chat?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>
|
9 |
+
Join us : 🌟TeamTonic🌟 is always making cool demos! Join our active builder's🛠️community on 👻Discord: [Discord](https://discord.gg/GWpVpekp) On 🤗Huggingface: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Polytonic](https://github.com/tonic-ai) & contribute to 🌟 [PolyGPT](https://github.com/tonic-ai/polygpt-alpha)
|
10 |
+
"""
|
11 |
+
# Load the quantized model
|
12 |
+
quant_dir = "llama-70b_2bit_quip"
|
13 |
+
quant_model = load_quantized_model(quant_dir).cuda()
|
14 |
+
tokenizer = AutoTokenizer.from_pretrained(quant_dir)
|
15 |
+
|
16 |
+
def generate_text(input_text):
|
17 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt").cuda()
|
18 |
+
output_ids = quant_model.generate(input_ids, do_sample=True)[0]
|
19 |
+
return tokenizer.decode(output_ids)
|
20 |
+
|
21 |
+
with gr.Blocks() as demo:
|
22 |
+
gr.Markdown(title)
|
23 |
+
gr.Markdown(description)
|
24 |
+
with gr.Row():
|
25 |
+
input_text = gr.Textbox(label="Enter text here", placeholder="Type something...", lines=2)
|
26 |
+
submit_button = gr.Button("Generate")
|
27 |
+
output_text = gr.Textbox(label="Generated Text", readonly=True)
|
28 |
+
|
29 |
+
submit_button.click(
|
30 |
+
fn=generate_text,
|
31 |
+
inputs=input_text,
|
32 |
+
outputs=output_text
|
33 |
+
)
|
34 |
+
|
35 |
+
demo.launch()
|