File size: 2,752 Bytes
0e42d9f
 
3c2f970
 
0e42d9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c2f970
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#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()