Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,81 @@
|
|
1 |
-
import
|
|
|
2 |
import gradio as gr
|
|
|
3 |
|
4 |
-
def sepia(input_img, strength):
|
5 |
-
sepia_filter = strength * np.array(
|
6 |
-
[[0.393, 0.769, 0.189], [0.349, 0.686, 0.168], [0.272, 0.534, 0.131]]
|
7 |
-
) + (1-strength) * np.identity(3)
|
8 |
-
sepia_img = input_img.dot(sepia_filter.T)
|
9 |
-
sepia_img /= sepia_img.max()
|
10 |
-
return sepia_img
|
11 |
-
|
12 |
-
callback = gr.CSVLogger()
|
13 |
-
|
14 |
-
with gr.Blocks() as demo:
|
15 |
-
with gr.Row():
|
16 |
-
with gr.Column():
|
17 |
-
img_input = gr.Image()
|
18 |
-
strength = gr.Slider(0, 1, 0.5)
|
19 |
-
img_output = gr.Image()
|
20 |
-
with gr.Row():
|
21 |
-
btn = gr.Button("Flag")
|
22 |
-
|
23 |
-
# This needs to be called at some point prior to the first call to callback.flag()
|
24 |
-
callback.setup([img_input, strength, img_output], "flagged_data_points")
|
25 |
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import warnings
|
3 |
import gradio as gr
|
4 |
+
import re
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
HF_TOKEN = os.getenv('HW_TOKEN')
|
8 |
+
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "save_audio")
|
9 |
+
|
10 |
+
|
11 |
+
cur_line=0
|
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 |
+
def readPromt():
|
39 |
+
global cur_line
|
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()
|