Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,80 +2,37 @@ import os
|
|
| 2 |
import warnings
|
| 3 |
import gradio as gr
|
| 4 |
import re
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
cur_line=-1
|
| 12 |
-
|
| 13 |
-
def readFile():
|
| 14 |
-
f=open('prompt.txt')
|
| 15 |
-
line_num=0
|
| 16 |
-
lines=f.readlines()
|
| 17 |
-
line_num = len(lines)
|
| 18 |
-
return line_num,lines
|
| 19 |
-
|
| 20 |
-
totlines,file_content=readFile()
|
| 21 |
-
|
| 22 |
-
#callback = gr.CSVLogger()
|
| 23 |
-
def recordAndsave(text,audio):
|
| 24 |
-
#print (next)
|
| 25 |
-
print (text)
|
| 26 |
-
global totlines
|
| 27 |
-
print(totlines)
|
| 28 |
-
global cur_line
|
| 29 |
-
if cur_line<totlines-1:
|
| 30 |
-
cur_line+=1
|
| 31 |
-
global file_content
|
| 32 |
-
print (cur_line)
|
| 33 |
-
return file_content[cur_line].strip()
|
| 34 |
-
#return None
|
| 35 |
-
|
| 36 |
-
#print (previous)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
cur_line+=1
|
| 41 |
-
global file_content
|
| 42 |
-
print (cur_line)
|
| 43 |
-
return file_content[cur_line]
|
| 44 |
-
|
| 45 |
-
def readNext():
|
| 46 |
-
|
| 47 |
-
global totlines
|
| 48 |
-
print(totlines)
|
| 49 |
-
global cur_line
|
| 50 |
-
if cur_line<totlines-1:
|
| 51 |
-
cur_line+=1
|
| 52 |
-
global file_content
|
| 53 |
-
print (cur_line)
|
| 54 |
-
return [file_content[cur_line],None]
|
| 55 |
-
|
| 56 |
-
def readPrevious():
|
| 57 |
-
global cur_line
|
| 58 |
-
if cur_line>=0:
|
| 59 |
-
cur_line-=1
|
| 60 |
-
#cur_line=current_line
|
| 61 |
-
global file_content
|
| 62 |
-
print (cur_line)
|
| 63 |
-
return [file_content[cur_line],None]
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
| 67 |
-
demo=gr.Interface(
|
| 68 |
-
fn=recordAndsave,
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
inputs=[
|
| 72 |
-
gr.Audio(sources=["microphone","upload"], type="filepath"),
|
| 73 |
-
|
| 74 |
-
],
|
| 75 |
-
outputs=[
|
| 76 |
-
gr.Textbox(readPromt(),label="Prompt")
|
| 77 |
-
],
|
| 78 |
-
|
| 79 |
-
allow_flagging="manual",
|
| 80 |
-
flagging_callback=hf_writer
|
| 81 |
-
).launch()
|
|
|
|
| 2 |
import warnings
|
| 3 |
import gradio as gr
|
| 4 |
import re
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
#HF_TOKEN = os.getenv('HW_TOKEN')
|
| 8 |
+
#hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
|
| 9 |
+
|
| 10 |
+
def sepia(input_img, strength):
|
| 11 |
+
sepia_filter = strength * np.array(
|
| 12 |
+
[[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
|
| 13 |
+
) + (1-strength) * np.identity(3)
|
| 14 |
+
sepia_img = input_img.dot(sepia_filter.T)
|
| 15 |
+
sepia_img /= sepia_img.max()
|
| 16 |
+
return sepia_img
|
| 17 |
+
|
| 18 |
+
callback = gr.CSVLogger()
|
| 19 |
+
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
with gr.Row():
|
| 22 |
+
with gr.Column():
|
| 23 |
+
img_input = gr.Image()
|
| 24 |
+
strength = gr.Slider(0, 1, 0.5)
|
| 25 |
+
img_output = gr.Image()
|
| 26 |
+
with gr.Row():
|
| 27 |
+
btn = gr.Button("Flag")
|
| 28 |
+
|
| 29 |
+
# This needs to be called at some point prior to the first call to callback.flag()
|
| 30 |
+
callback.setup([img_input, strength, img_output], "flagged_data_points")
|
| 31 |
|
| 32 |
+
img_input.change(sepia, [img_input, strength], img_output)
|
| 33 |
+
strength.change(sepia, [img_input, strength], img_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
# We can choose which components to flag -- in this case, we'll flag all of them
|
| 36 |
+
btn.click(lambda *args: callback.flag(args), [img_input, strength, img_output], None, preprocess=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|