Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -89,76 +89,76 @@
|
|
89 |
|
90 |
# demo.launch()
|
91 |
|
92 |
-
|
93 |
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
|
115 |
|
116 |
-
|
117 |
|
118 |
-
|
119 |
-
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
|
131 |
-
|
132 |
|
133 |
-
import numpy as np
|
134 |
-
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
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 |
-
|
156 |
-
|
157 |
|
158 |
-
|
159 |
-
|
160 |
|
161 |
-
|
162 |
-
|
163 |
|
164 |
-
demo.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")
|
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](https://huggingface.co/Sajjo/crowdsourced)",
|
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()
|