Sajjo commited on
Commit
7b0cd17
·
verified ·
1 Parent(s): 0b26145

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -31
app.py CHANGED
@@ -89,43 +89,76 @@
89
 
90
  # demo.launch()
91
 
92
- import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
93
 
 
 
 
 
 
 
 
94
 
95
- def calculator(num1, operation, num2):
96
- if operation == "add":
97
- return num1 + num2
98
- elif operation == "subtract":
99
- return num1 - num2
100
- elif operation == "multiply":
101
- return num1 * num2
102
- elif operation == "divide":
103
- return num1 / num2
104
 
 
105
 
106
- iface = gr.Interface(
107
- calculator,
108
- ["number", gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
109
- "number",
110
- allow_flagging="manual",
111
- flagging_options=["correct", "wrong"]
112
- )
113
 
114
- iface.launch()
 
 
 
 
 
 
 
 
115
 
116
- import os
117
 
118
- HF_TOKEN = os.getenv('HF_TOKEN')
119
- hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "crowdsourced-calculator-demo")
120
 
121
- iface = gr.Interface(
122
- calculator,
123
- ["number", gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
124
- "number",
125
- description="Check out the crowd-sourced dataset at: [https://huggingface.co/Sajjo/crowdsourced-calculator-demo](https://huggingface.co/Sajjo/crowdsourced-calculator-demo)",
126
- allow_flagging="manual",
127
- flagging_options=["wrong sign", "off by one", "other"],
128
- flagging_callback=hf_writer
129
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
 
131
- iface.launch()
 
89
 
90
  # demo.launch()
91
 
92
+ # import gradio as gr
93
+
94
+
95
+ # def calculator(num1, operation, num2):
96
+ # if operation == "add":
97
+ # return num1 + num2
98
+ # elif operation == "subtract":
99
+ # return num1 - num2
100
+ # elif operation == "multiply":
101
+ # return num1 * num2
102
+ # elif operation == "divide":
103
+ # return num1 / num2
104
+
105
 
106
+ # iface = gr.Interface(
107
+ # calculator,
108
+ # ["number", gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
109
+ # "number",
110
+ # allow_flagging="manual",
111
+ # flagging_options=["correct", "wrong"]
112
+ # )
113
 
114
+ # iface.launch()
 
 
 
 
 
 
 
 
115
 
116
+ # import os
117
 
118
+ # HF_TOKEN = os.getenv('HF_TOKEN')
119
+ # hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "crowdsourced-calculator-demo")
 
 
 
 
 
120
 
121
+ # iface = gr.Interface(
122
+ # calculator,
123
+ # ["number", gr.Radio(["add", "subtract", "multiply", "divide"]), "number"],
124
+ # "number",
125
+ # description="Check out the crowd-sourced dataset at: [https://huggingface.co/Sajjo/crowdsourced-calculator-demo](https://huggingface.co/Sajjo/crowdsourced-calculator-demo)",
126
+ # allow_flagging="manual",
127
+ # flagging_options=["wrong sign", "off by one", "other"],
128
+ # flagging_callback=hf_writer
129
+ # )
130
 
131
+ # iface.launch()
132
 
133
+ import numpy as np
134
+ import gradio as gr
135
 
136
+ def sepia(input_img, strength):
137
+ sepia_filter = strength * np.array(
138
+ [[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
139
+ ) + (1-strength) * np.identity(3)
140
+ sepia_img = input_img.dot(sepia_filter.T)
141
+ sepia_img /= sepia_img.max()
142
+ return sepia_img
143
+
144
+ callback = gr.CSVLogger()
145
+
146
+ with gr.Blocks() as demo:
147
+ with gr.Row():
148
+ with gr.Column():
149
+ img_input = gr.Image()
150
+ strength = gr.Slider(0, 1, 0.5)
151
+ img_output = gr.Image()
152
+ with gr.Row():
153
+ btn = gr.Button("Flag")
154
+
155
+ # This needs to be called at some point prior to the first call to callback.flag()
156
+ callback.setup([img_input, strength, img_output], "flagged_data_points")
157
+
158
+ img_input.change(sepia, [img_input, strength], img_output)
159
+ strength.change(sepia, [img_input, strength], img_output)
160
+
161
+ # We can choose which components to flag -- in this case, we'll flag all of them
162
+ btn.click(lambda *args: callback.flag(args), [img_input, strength, img_output], None, preprocess=False)
163
 
164
+ demo.launch()