Spaces:
Runtime error
Runtime error
Commit
·
a600446
1
Parent(s):
b60d21c
Add application and requirements file
Browse files- app.py +74 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers import AutoTokenizer
|
| 2 |
+
import transformers
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import fire
|
| 6 |
+
import torch
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def main(
|
| 11 |
+
base_model="ise-uiuc/Magicoder-S-DS-6.7B",
|
| 12 |
+
device="cpu",
|
| 13 |
+
port=8070,
|
| 14 |
+
):
|
| 15 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model)
|
| 16 |
+
pipeline = transformers.pipeline(
|
| 17 |
+
"text-generation",
|
| 18 |
+
model=base_model,
|
| 19 |
+
torch_dtype=torch.float16,
|
| 20 |
+
device=device
|
| 21 |
+
)
|
| 22 |
+
def evaluate_magicoder(
|
| 23 |
+
instruction,
|
| 24 |
+
temperature=1,
|
| 25 |
+
max_new_tokens=2048,
|
| 26 |
+
):
|
| 27 |
+
MAGICODER_PROMPT = """You are an exceptionally intelligent coding assistant that consistently delivers accurate and reliable responses to user instructions.
|
| 28 |
+
|
| 29 |
+
@@ Instruction
|
| 30 |
+
{instruction}
|
| 31 |
+
|
| 32 |
+
@@ Response
|
| 33 |
+
"""
|
| 34 |
+
prompt = MAGICODER_PROMPT.format(instruction=instruction)
|
| 35 |
+
|
| 36 |
+
if temperature > 0:
|
| 37 |
+
sequences = pipeline(
|
| 38 |
+
prompt,
|
| 39 |
+
do_sample=True,
|
| 40 |
+
temperature=temperature,
|
| 41 |
+
max_new_tokens=max_new_tokens,
|
| 42 |
+
)
|
| 43 |
+
else:
|
| 44 |
+
sequences = pipeline(
|
| 45 |
+
prompt,
|
| 46 |
+
max_new_tokens=max_new_tokens,
|
| 47 |
+
)
|
| 48 |
+
for seq in sequences:
|
| 49 |
+
generated_text = seq['generated_text'].replace(prompt, "")
|
| 50 |
+
return generated_text
|
| 51 |
+
|
| 52 |
+
gr.Interface(
|
| 53 |
+
fn=evaluate_magicoder,
|
| 54 |
+
inputs=[
|
| 55 |
+
gr.components.Textbox(
|
| 56 |
+
lines=3, label="Instruction", placeholder="Anything you want to ask Magicoder ?"
|
| 57 |
+
),
|
| 58 |
+
gr.components.Slider(minimum=0, maximum=1, value=0, label="Temperature"),
|
| 59 |
+
gr.components.Slider(
|
| 60 |
+
minimum=1, maximum=2048, step=1, value=1024, label="Max tokens"
|
| 61 |
+
),
|
| 62 |
+
],
|
| 63 |
+
outputs=[
|
| 64 |
+
gr.components.Textbox(
|
| 65 |
+
lines=30,
|
| 66 |
+
label="Output",
|
| 67 |
+
)
|
| 68 |
+
],
|
| 69 |
+
title="Magicoder",
|
| 70 |
+
description="This is a LLM playground for Magicoder! Follow us on Github: https://github.com/ise-uiuc/magicoder and Huggingface: https://huggingface.co/ise-uiuc."
|
| 71 |
+
).queue().launch(share=True, server_port=port)
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
fire.Fire(main)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fire==0.5.0
|
| 2 |
+
torch==2.1.1
|
| 3 |
+
transformers==4.35.2
|