|
|
|
|
|
|
|
import transformers |
|
import streamlit as st |
|
from PIL import Image |
|
|
|
from transformers import RobertaTokenizer, T5ForConditionalGeneration |
|
|
|
@st.cache_resource |
|
def load_model(model_name): |
|
|
|
model = T5ForConditionalGeneration.from_pretrained("hanbin/MaMaL-Com") |
|
|
|
tokenizer = RobertaTokenizer.from_pretrained("hanbin/MaMaL-Com") |
|
return model,tokenizer |
|
|
|
|
|
|
|
|
|
|
|
def main(model,tokenizer): |
|
|
|
|
|
st.set_page_config( |
|
layout="centered", page_title="MaMaL-Gen Demo(代码生成)", page_icon="❄️" |
|
) |
|
|
|
c1, c2 = st.columns([0.32, 2]) |
|
|
|
|
|
|
|
with c1: |
|
st.image( |
|
"images/panda.png", |
|
width=100, |
|
) |
|
|
|
|
|
|
|
with c2: |
|
st.caption("") |
|
st.title("MaMaL-Gen(代码生成)") |
|
|
|
|
|
|
|
|
|
st.sidebar.image("images/panda.png",width=270) |
|
|
|
st.sidebar.write("") |
|
|
|
|
|
|
|
|
|
|
|
API_KEY = st.sidebar.text_input( |
|
"Enter your HuggingFace API key", |
|
help="Once you created you HuggingFace account, you can get your free API token in your settings page: https://huggingface.co/settings/tokens", |
|
type="password", |
|
) |
|
|
|
|
|
API_URL = "https://api-inference.huggingface.co/models/valhalla/distilbart-mnli-12-3" |
|
|
|
|
|
headers = {"Authorization": f"Bearer {API_KEY}"} |
|
|
|
|
|
st.sidebar.markdown("---") |
|
|
|
|
|
|
|
|
|
st.sidebar.write( |
|
""" |
|
App 由 东北大学NLP课小组成员创建, 使用 [Streamlit](https://streamlit.io/)🎈 和 [HuggingFace](https://huggingface.co/inference-api)'s [MaMaL-Gen](https://huggingface.co/hanbin/MaMaL-Gen) 模型. |
|
""" |
|
) |
|
|
|
if __name__ == '__main__': |
|
model, tokenizer = load_model("hanbin/MaMaL-Gen") |
|
main(model, tokenizer) |