Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How i build a UI demo like mentioned in readme (input to output ) #66

Open
prameelareddi opened this issue Jun 16, 2023 · 1 comment
Open

Comments

@prameelareddi
Copy link

How i build a UI demo like mentioned in the readme (input to output )

https://github.com/salesforce/CodeGen/blob/main/assets/two.gif

@AndreasMeyerSFDC
Copy link

AndreasMeyerSFDC commented Jul 4, 2023

@prameela1610 the easiest way is to use gradio. Here is a code snippet implementing the demo:

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import gradio as gr

tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-7B")
model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-7B", trust_remote_code=True, revision="main")

def generate_code(input_text):
    inputs = tokenizer(input_text, return_tensors="pt")
    sample = model.generate(**inputs, max_length=128)
    generated_code = tokenizer.decode(sample[0], truncate_before_pattern=[r"\n\n^#", "^'''", "\n\n\n"])
    return generated_code

inputs = gr.inputs.Textbox(label="Input Text")
outputs = gr.outputs.Textbox(label="Generated Code")
interface = gr.Interface(fn=generate_code, inputs=inputs, outputs=outputs)

interface.launch()

pip install gradio will do the trick ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants