#pip install transformers #pip install gradio import gradio as gr from transformers import AutoTokenizer, AutoModelForCausalLM from transformers import pipeline tokenizer = AutoTokenizer.from_pretrained('gpt2') model = AutoModelForCausalLM.from_pretrained('gpt2') #model = AutoModelForSeq2SeqLM.from_pretrained("t5-base") #set theme import gradio as gr from gradio.themes.base import Base from gradio.themes.utils import colors, fonts, sizes theme = gr.themes.Base( primary_hue="pink", secondary_hue="pink", neutral_hue="pink", font=[gr.themes.GoogleFont('Merriweather'), 'ui-sans-serif', 'system-ui', 'sans-serif'], ).set( body_text_color='*primary_500', body_text_color_dark='*secondary_600', body_text_weight='500', background_fill_primary='*primary_50', background_fill_secondary='*primary_100', border_color_accent='*primary_400', button_border_width='*block_label_border_width' ) def prompt_fx(text): translator = pipeline( model=model, tokenizer=tokenizer ) response = translator(text) return response def clear_out(): return "" with gr.Blocks(theme=theme) as demo: gr.Markdown( """ # AI for all """) with gr.Tab("Home"): prompt = gr.Textbox(label="Enter prompt here:") output = gr.Textbox(label="Response") with gr.Row(): button = gr.Button("Submit", variant="primary") clear = gr.Button("Clear") button.click(fn=prompt_fx, inputs=prompt, outputs=output) clear.click(fn=clear_out, outputs=prompt) with gr.Tab("About"): gr.Markdown( """ AI for All is a fine-tuned version of Open AI's GPT2 model. It was fine-tuned using readings from important scholars on power dynamics and how they affect oppressed people. Examples include Walter Rodney, Angela Davis, and Audre Lorde. Technical specifics can be found on the [HuggingFace page](https://link-url-here.org). The goal of this project is to center marginalized voices. Because of the way our society is structured, we are never considered first. Efforts towards the advancement of technology frequently ignore the struggles of oppressed people, so in this project I am **finally** creating something for us. """) with gr.Accordion("Quick Links"): gr.Markdown(""" [HuggingFace page](https://link-url-here.org) [GitHub](https://link-url-here.org) """) def greet(name): return "Hello " + name + "!!" iface = gr.Interface(fn=greet, inputs="text", outputs="text") iface.launch()