Spaces:
Runtime error
Runtime error
tonic
commited on
Commit
·
f4b9dcc
1
Parent(s):
1b4f65b
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import spaces
|
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
import transformers
|
5 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
6 |
import os
|
7 |
|
8 |
title = """# Welcome to 🌟Tonic's✨StarCoder
|
@@ -14,28 +14,13 @@ default_system_prompt = """SYSTEM: You are an AI that code. Answer with code."""
|
|
14 |
|
15 |
model_path = "bigcode/starcoder2-15b"
|
16 |
|
17 |
-
|
18 |
hf_token = os.getenv("HF_TOKEN")
|
19 |
if not hf_token:
|
20 |
raise ValueError("Hugging Face token not found. Please set the HF_TOKEN environment variable.")
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
device_map="auto",
|
26 |
-
# trust_remote_code=True,
|
27 |
-
token=hf_token,
|
28 |
-
)
|
29 |
-
|
30 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
|
31 |
-
|
32 |
-
# import gradio as gr
|
33 |
-
# from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
|
34 |
-
|
35 |
-
# checkpoint = "bigcode/starcoder2-15b"
|
36 |
-
# quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
37 |
-
# tokenizer = AutoTokenizer.from_pretrained(checkpoint)
|
38 |
-
# model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config).to("cuda")
|
39 |
@spaces.GPU
|
40 |
def generate_text(prompt, temperature, max_length):
|
41 |
inputs = tokenizer.encode(prompt, return_tensors="pt").to("cuda")
|
@@ -45,14 +30,12 @@ def generate_text(prompt, temperature, max_length):
|
|
45 |
def gradio_app():
|
46 |
with gr.Blocks() as demo:
|
47 |
gr.Markdown(title)
|
48 |
-
|
49 |
-
with gr.Row():
|
50 |
-
generate_btn = gr.Button("Generate")
|
51 |
with gr.Row():
|
52 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.5, label="Temperature")
|
53 |
max_length = gr.Slider(minimum=100, maximum=1024, step=10, value=100, label="Generate Length")
|
54 |
-
|
55 |
-
|
56 |
|
57 |
generate_btn.click(
|
58 |
fn=generate_text,
|
@@ -60,4 +43,7 @@ def gradio_app():
|
|
60 |
outputs=output
|
61 |
)
|
62 |
|
63 |
-
demo.launch()
|
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
import transformers
|
5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
6 |
import os
|
7 |
|
8 |
title = """# Welcome to 🌟Tonic's✨StarCoder
|
|
|
14 |
|
15 |
model_path = "bigcode/starcoder2-15b"
|
16 |
|
|
|
17 |
hf_token = os.getenv("HF_TOKEN")
|
18 |
if not hf_token:
|
19 |
raise ValueError("Hugging Face token not found. Please set the HF_TOKEN environment variable.")
|
20 |
|
21 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
22 |
+
quantization_config = BitsAndBytesConfig(load_in_8bit=True)
|
23 |
+
model = AutoModelForCausalLM.from_pretrained( model_path, quantization_config=quantization_config).to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
@spaces.GPU
|
25 |
def generate_text(prompt, temperature, max_length):
|
26 |
inputs = tokenizer.encode(prompt, return_tensors="pt").to("cuda")
|
|
|
30 |
def gradio_app():
|
31 |
with gr.Blocks() as demo:
|
32 |
gr.Markdown(title)
|
33 |
+
prompt = gr.Textbox(label="Enter your code prompt", placeholder="def print_hello_world():")
|
|
|
|
|
34 |
with gr.Row():
|
35 |
temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, value=0.5, label="Temperature")
|
36 |
max_length = gr.Slider(minimum=100, maximum=1024, step=10, value=100, label="Generate Length")
|
37 |
+
generate_btn = gr.Button("Try✨StarCoder")
|
38 |
+
output = gr.Code(label="Generated Code", lines=40)
|
39 |
|
40 |
generate_btn.click(
|
41 |
fn=generate_text,
|
|
|
43 |
outputs=output
|
44 |
)
|
45 |
|
46 |
+
demo.launch()
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
gradio_app()
|