Spaces:
Build error
Build error
app.py
CHANGED
@@ -4,32 +4,52 @@ import gradio as gr
|
|
4 |
import whisper
|
5 |
|
6 |
model = whisper.load_model("base")
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def fun(audio) : #, state=''):
|
9 |
-
|
10 |
-
|
11 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
def fun1(audio, state=''):
|
14 |
text = model.transcribe(audio)["text"]
|
15 |
state += text + " "
|
16 |
return state, state
|
17 |
|
18 |
-
# Set the starting state to an empty string
|
19 |
-
|
20 |
-
#gr.Interface(
|
21 |
-
# fn=transcribe,
|
22 |
-
# inputs=[
|
23 |
-
# gr.Audio(source="microphone", type="filepath", streaming=True),
|
24 |
-
# "state"
|
25 |
-
# ],
|
26 |
-
# outputs=[
|
27 |
-
# "textbox",
|
28 |
-
# "state"
|
29 |
-
# ],
|
30 |
-
# live=True).launch()
|
31 |
-
|
32 |
-
|
33 |
gr.Interface(
|
34 |
title = 'Testing Whisper',
|
35 |
fn=fun,
|
@@ -38,6 +58,6 @@ gr.Interface(
|
|
38 |
# "state"
|
39 |
],
|
40 |
outputs=[
|
41 |
-
"textbox",
|
42 |
],
|
43 |
live=True).launch()
|
|
|
4 |
import whisper
|
5 |
|
6 |
model = whisper.load_model("base")
|
7 |
+
##Bloom
|
8 |
+
API_URL = "https://api-inference.huggingface.co/models/bigscience/bloom"
|
9 |
+
HF_TOKEN = os.environ["HF_TOKEN"]
|
10 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
11 |
+
|
12 |
|
13 |
def fun(audio) : #, state=''):
|
14 |
+
text1 = model.transcribe(audio)["text"]
|
15 |
+
text2 = lang_model_response(text)
|
16 |
+
return text1, text2
|
17 |
+
|
18 |
+
def lang_model_response(prompt):
|
19 |
+
print(f"*****Inside meme_generate - Prompt is :{prompt}")
|
20 |
+
if len(prompt) == 0:
|
21 |
+
prompt = """Can you help me please?"""
|
22 |
+
|
23 |
+
json_ = {"inputs": prompt,
|
24 |
+
"parameters":
|
25 |
+
{
|
26 |
+
"top_p": top_p, #0.90 default
|
27 |
+
"max_new_tokens": 64,
|
28 |
+
"temperature": temp, #1.1 default
|
29 |
+
"return_full_text": True,
|
30 |
+
"do_sample": True,
|
31 |
+
},
|
32 |
+
"options":
|
33 |
+
{"use_cache": True,
|
34 |
+
"wait_for_model": True,
|
35 |
+
},}
|
36 |
+
response = requests.post(API_URL, headers=headers, json=json_)
|
37 |
+
print(f"Response is : {response}")
|
38 |
+
output = response.json()
|
39 |
+
print(f"output is : {output}")
|
40 |
+
output_tmp = output[0]['generated_text']
|
41 |
+
print(f"output_tmp is: {output_tmp}")
|
42 |
+
solution = output_tmp[0] #output_tmp.split("\nQ:")[0]
|
43 |
+
print(f"Final response after splits is: {solution}")
|
44 |
+
|
45 |
+
#meme_image, new_prompt = write_on_image(solution)
|
46 |
+
return solution
|
47 |
|
48 |
def fun1(audio, state=''):
|
49 |
text = model.transcribe(audio)["text"]
|
50 |
state += text + " "
|
51 |
return state, state
|
52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
gr.Interface(
|
54 |
title = 'Testing Whisper',
|
55 |
fn=fun,
|
|
|
58 |
# "state"
|
59 |
],
|
60 |
outputs=[
|
61 |
+
"textbox", "textbox"
|
62 |
],
|
63 |
live=True).launch()
|