shalinialisha commited on
Commit
0e42d9f
β€’
1 Parent(s): 3c2f970
Files changed (1) hide show
  1. app.py +84 -0
app.py CHANGED
@@ -1,5 +1,89 @@
 
 
1
  import gradio as gr
2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  def greet(name):
4
  return "Hello " + name + "!!"
5
 
 
1
+ #pip install transformers
2
+ #pip install gradio
3
  import gradio as gr
4
 
5
+ from transformers import AutoTokenizer, AutoModelForCausalLM
6
+ from transformers import pipeline
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained('gpt2')
9
+ model = AutoModelForCausalLM.from_pretrained('gpt2')
10
+
11
+ #model = AutoModelForSeq2SeqLM.from_pretrained("t5-base")
12
+
13
+ #set theme
14
+ import gradio as gr
15
+ from gradio.themes.base import Base
16
+ from gradio.themes.utils import colors, fonts, sizes
17
+
18
+ theme = gr.themes.Base(
19
+ primary_hue="pink",
20
+ secondary_hue="pink",
21
+ neutral_hue="pink",
22
+ font=[gr.themes.GoogleFont('Merriweather'), 'ui-sans-serif', 'system-ui', 'sans-serif'],
23
+ ).set(
24
+ body_text_color='*primary_500',
25
+ body_text_color_dark='*secondary_600',
26
+ body_text_weight='500',
27
+ background_fill_primary='*primary_50',
28
+ background_fill_secondary='*primary_100',
29
+ border_color_accent='*primary_400',
30
+ button_border_width='*block_label_border_width'
31
+ )
32
+
33
+
34
+ def prompt_fx(text):
35
+ translator = pipeline(
36
+ model=model,
37
+ tokenizer=tokenizer
38
+ )
39
+ response = translator(text)
40
+ return response
41
+
42
+ def clear_out():
43
+ return ""
44
+
45
+
46
+ with gr.Blocks(theme=theme) as demo:
47
+
48
+ gr.Markdown(
49
+ """
50
+ # AI for all
51
+ """)
52
+
53
+
54
+ with gr.Tab("Home"):
55
+ prompt = gr.Textbox(label="Enter prompt here:")
56
+ output = gr.Textbox(label="Response")
57
+ with gr.Row():
58
+ button = gr.Button("Submit", variant="primary")
59
+ clear = gr.Button("Clear")
60
+ button.click(fn=prompt_fx, inputs=prompt, outputs=output)
61
+ clear.click(fn=clear_out, outputs=prompt)
62
+
63
+ with gr.Tab("About"):
64
+ gr.Markdown(
65
+ """
66
+ AI for All is a fine-tuned version of Open AI's GPT2 model. It was
67
+ fine-tuned using readings from important scholars on power dynamics
68
+ and how they affect oppressed people. Examples include Walter Rodney,
69
+ Angela Davis, and Audre Lorde. Technical specifics can be found on
70
+ the [HuggingFace page](https://link-url-here.org).
71
+
72
+ The goal of this project is to center marginalized voices. Because
73
+ of the way our society is structured, we are never considered
74
+ first. Efforts towards the advancement of technology frequently
75
+ ignore the struggles of oppressed people, so in this project I am
76
+ **finally** creating something for us.
77
+ """)
78
+
79
+
80
+ with gr.Accordion("Quick Links"):
81
+ gr.Markdown("""
82
+ [HuggingFace page](https://link-url-here.org)
83
+ [GitHub](https://link-url-here.org)
84
+ """)
85
+
86
+
87
  def greet(name):
88
  return "Hello " + name + "!!"
89