Chris Jackett commited on
Commit
075b08e
1 Parent(s): 758f8d6

Implement gradio app.

Browse files
Files changed (2) hide show
  1. app.py +65 -4
  2. requirements.txt +3 -1
app.py CHANGED
@@ -1,7 +1,68 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ from transformers import pipeline
 
4
 
5
+ pipe = pipeline("text-generation", model="tiiuae/falcon-7b-instruct", trust_remote_code=True)
6
+ # flan-t5-small doesn't work very well
7
+ # pipe = pipeline("text2text-generation", model="google/flan-t5-small", trust_remote_code=True, max_length=500)
8
+
9
+ with gr.Blocks(title="Kind Words - Gradio") as demo:
10
+
11
+ gr.Markdown(
12
+ """
13
+ # Kind Words - Gradio
14
+ Please fill in the details below to create kind words
15
+ """)
16
+ with gr.Group():
17
+ name_box = gr.Textbox(label="Name", value="Emily")
18
+ situation_box = gr.Textbox(label="Situation", value="Writing a scientific blog post about using AI to protect deep-sea coral reefs")
19
+ behavior_box = gr.Textbox(label="Behavior", value="Emily interacted professionally and efficiently, was open to making modifications based on feedback and worked proficiently with the time constraints of others")
20
+ impact_box = gr.Textbox(label="Impact", value="A professional and engaging science blog post was created that communicated our science well")
21
+ with gr.Row():
22
+ perspective_dropdown = gr.Dropdown(["First Person", "Third Person"], label="Perspective", value="Third Person")
23
+ length_dropdown = gr.Dropdown(["Short", "Medium", "Long"], label="Output length", value="Medium")
24
+ praise_dropdown = gr.Dropdown(["Minimal", "Modest", "High"], label="Praise level", value="Modest")
25
+
26
+ submit_btn = gr.Button("Submit")
27
+
28
+ error_box = gr.Textbox(label="Error", visible=False)
29
+
30
+ with gr.Column(visible=False) as output_col:
31
+ output_box = gr.Textbox(label="Output")
32
+
33
+ def submit(name, situation, behavior, impact, perspective, length, praise):
34
+ if len(name) == 0:
35
+ return {error_box: gr.update(value="Enter name", visible=True)}
36
+ elif len(situation) == 0:
37
+ return {error_box: gr.update(value="Enter a description of the situation", visible=True)}
38
+ elif len(behavior) == 0:
39
+ return {error_box: gr.update(value="Enter a description of the behavior", visible=True)}
40
+ elif len(impact) == 0:
41
+ return {error_box: gr.update(value="Enter a description of the impact", visible=True)}
42
+
43
+ if length == "Short":
44
+ output_length = "a short paragraph"
45
+ elif length == "Long":
46
+ output_length = "several paragraphs"
47
+ else:
48
+ output_length = "a couple of paragraphs "
49
+
50
+ prompt = f"""Write {output_length} in a {perspective.lower()} perspective providing positive feedback with {praise.lower()} praise using the following details:
51
+ Name: {name}
52
+ Situation: {situation}
53
+ Behavior: {behavior}
54
+ Impact: {impact}"""
55
+
56
+ return {
57
+ output_col: gr.update(visible=True),
58
+ # output_box: prompt,
59
+ output_box: pipe(prompt)[0]["generated_text"],
60
+ }
61
+
62
+ submit_btn.click(
63
+ submit,
64
+ [name_box, situation_box, behavior_box, impact_box, perspective_dropdown, length_dropdown, praise_dropdown],
65
+ [error_box, output_box, output_col],
66
+ )
67
+
68
+ demo.launch()
requirements.txt CHANGED
@@ -1 +1,3 @@
1
- gradio
 
 
 
1
+ gradio
2
+ transformers
3
+ torch