stablecode2 / app.py
Tonic's picture
Update app.py
c0af598 verified
raw
history blame
2.84 kB
import spaces
import gradio as gr
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
title = "# 👋🏻Welcome to🌟Tonic's⚖️StableCode2"
description = """⚖️StableCode2 is a small sized coding llm that performs well in python ! You can also use [⚖️stabilityai/stable-code-3b](https://huggingface.co/stabilityai/stable-code-3b) by cloning this space. 🧬🔬🔍 Simply click here: <a style="display:inline-block" href="https://huggingface.co/spaces/Tonic/stablecode2?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>
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: [TeamTonic](https://huggingface.co/TeamTonic) & [MultiTransformer](https://huggingface.co/MultiTransformer) On 🌐Github: [Tonic-AI](https://github.com/tonic-ai) & contribute to 🌟 [EasyAGI](https://github.com/tonic-ai/EasyAGI) 🤗Big thanks to Ythe folks at huggingface for the ZeroGPU 🤗
To contribute to this space make a PR with a new example or cool new use-case for this one 🤗
"""
tokenizer = AutoTokenizer.from_pretrained(
"stabilityai/stable-code-3b", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
"stabilityai/stable-code-3b",
trust_remote_code=True,
torch_dtype="auto",
# attn_implementation="flash_attention_2",
).to("cuda" if torch.cuda.is_available() else "cpu")
@spaces.GPU
def generate_code(prompt):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
tokens = model.generate(
**inputs,
max_new_tokens=650,
temperature=0.3,
do_sample=False,
)
generated_code = tokenizer.decode(tokens[0], skip_special_tokens=True)
return generated_code
with gr.Blocks() as demo:
gr.Markdown(title)
gr.Markdown(description)
with gr.Row():
prompt = gr.Textbox(lines=2, placeholder="Enter your Python code prompt")
output = gr.Textbox(label = "⚖️StableCode2")
generate_button = gr.Button("Generate")
generate_button.click(fn=generate_code, inputs=prompt, outputs=output)
demo.launch()