Spaces:
Runtime error
Runtime error
Download app.py from PinoCorgi/CodeExplainerPython: direct link, hf CLI and curl.
- Browser
- Download file 677 Bytes
-
https://huggingface.co/spaces/PinoCorgi/CodeExplainerPython/resolve/cfabc73108d39eb03c0b2b7d72999bb99fccafe4/app.py
- Command line
-
hf download hf://spaces/PinoCorgi/CodeExplainerPython@cfabc73108d39eb03c0b2b7d72999bb99fccafe4/app.py
-
curl -L -o app.py https://huggingface.co/spaces/PinoCorgi/CodeExplainerPython/resolve/cfabc73108d39eb03c0b2b7d72999bb99fccafe4/app.py
677 Bytes
| import gradio as gr | |
| from transformers import ( | |
| AutoModelForSeq2SeqLM, | |
| AutoTokenizer, | |
| AutoConfig, | |
| pipeline, | |
| ) | |
| model_name = "sagard21/python-code-explainer" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name, padding=True) | |
| model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
| config = AutoConfig.from_pretrained(model_name) | |
| model.eval() | |
| pipe = pipeline("summarization", model=model_name, config=config, tokenizer=tokenizer) | |
| def generate_text(text_prompt): | |
| response = pipe(text_prompt) | |
| return response[0]['summary_text'] | |
| textbox = gr.Textbox() | |
| demo = gr.Interface(generate_text, textbox, textbox) | |
| if __name__ == "__main__": | |
| demo.launch() |