Spaces:
Running
on
Zero
Running
on
Zero
Added gradio_client API
Browse files- .gitignore +1 -0
- app.py +20 -39
- requirements.txt +1 -0
.gitignore
CHANGED
@@ -9,3 +9,4 @@ build/
|
|
9 |
.DS_Store
|
10 |
*.zip
|
11 |
*.wav
|
|
|
|
9 |
.DS_Store
|
10 |
*.zip
|
11 |
*.wav
|
12 |
+
.venv/
|
app.py
CHANGED
@@ -2,38 +2,23 @@ import gradio as gr
|
|
2 |
import spaces
|
3 |
import os, torch, io
|
4 |
import json
|
5 |
-
|
6 |
-
os.system("python -m unidic download")
|
7 |
import httpx
|
8 |
-
|
9 |
# print("Make sure you've downloaded unidic (python -m unidic download) for this WebUI to work.")
|
10 |
from melo.api import TTS
|
11 |
import tempfile
|
12 |
import wave
|
13 |
from pydub import AudioSegment
|
14 |
-
from
|
15 |
-
AutoModelForCausalLM,
|
16 |
-
AutoTokenizer,
|
17 |
-
BitsAndBytesConfig,
|
18 |
-
)
|
19 |
-
|
20 |
-
quantization_config = BitsAndBytesConfig(
|
21 |
-
load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16
|
22 |
-
)
|
23 |
-
|
24 |
-
model = AutoModelForCausalLM.from_pretrained(
|
25 |
-
"NousResearch/Hermes-2-Pro-Llama-3-8B",
|
26 |
-
quantization_config=quantization_config,
|
27 |
-
)
|
28 |
-
tok = AutoTokenizer.from_pretrained("NousResearch/Hermes-2-Pro-Llama-3-8B")
|
29 |
-
terminators = [tok.eos_token_id, tok.convert_tokens_to_ids("<|eot_id|>")]
|
30 |
-
|
31 |
|
|
|
32 |
def fetch_text(url):
|
33 |
print("Entered Webpage Extraction")
|
34 |
prefix_url = "https://r.jina.ai/"
|
35 |
url = prefix_url + url
|
36 |
-
response = httpx.get(url, timeout=
|
|
|
37 |
return response.text
|
38 |
|
39 |
|
@@ -51,23 +36,19 @@ def synthesize(article_url, progress=gr.Progress()):
|
|
51 |
}
|
52 |
"""
|
53 |
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
messages = tok.apply_chat_template(chat, tokenize=False, add_generation_prompt=True)
|
61 |
-
model_inputs = tok([messages], return_tensors="pt").to(device)
|
62 |
-
|
63 |
-
text = model.generate(
|
64 |
-
model_inputs,
|
65 |
-
max_new_tokens=1024,
|
66 |
-
do_sample=True,
|
67 |
-
temperature=0.9,
|
68 |
-
eos_token_id=terminators,
|
69 |
)
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
71 |
speed = 1.0
|
72 |
models = {
|
73 |
"EN": TTS(language="EN", device=device),
|
@@ -75,7 +56,7 @@ def synthesize(article_url, progress=gr.Progress()):
|
|
75 |
speakers = ["EN-Default", "EN-US"]
|
76 |
|
77 |
combined_audio = AudioSegment.empty()
|
78 |
-
conversation = json.loads(
|
79 |
for i, turn in enumerate(conversation["conversation"]):
|
80 |
bio = io.BytesIO()
|
81 |
text = turn["text"]
|
@@ -103,4 +84,4 @@ with gr.Blocks() as demo:
|
|
103 |
aud = gr.Audio(interactive=False)
|
104 |
btn.click(synthesize, inputs=[text], outputs=[aud])
|
105 |
|
106 |
-
demo.queue(api_open=True, default_concurrency_limit=10).launch(show_api=True)
|
|
|
2 |
import spaces
|
3 |
import os, torch, io
|
4 |
import json
|
5 |
+
import re
|
6 |
+
# os.system("python -m unidic download")
|
7 |
import httpx
|
|
|
8 |
# print("Make sure you've downloaded unidic (python -m unidic download) for this WebUI to work.")
|
9 |
from melo.api import TTS
|
10 |
import tempfile
|
11 |
import wave
|
12 |
from pydub import AudioSegment
|
13 |
+
from gradio_client import Client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
+
client = Client("eswardivi/AIO_Chat")
|
16 |
def fetch_text(url):
|
17 |
print("Entered Webpage Extraction")
|
18 |
prefix_url = "https://r.jina.ai/"
|
19 |
url = prefix_url + url
|
20 |
+
response = httpx.get(url, timeout=120.0)
|
21 |
+
print("Response Received")
|
22 |
return response.text
|
23 |
|
24 |
|
|
|
36 |
}
|
37 |
"""
|
38 |
|
39 |
+
result = client.predict(
|
40 |
+
f"{text} \n Convert the text as Elaborate Conversation between two people as Podcast.\nfollowing this template and return only JSON \n {template}",
|
41 |
+
0.9,
|
42 |
+
True,
|
43 |
+
1024,
|
44 |
+
api_name="/chat"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
)
|
46 |
+
pattern = r"\{(?:[^{}]|(?:\{[^{}]*\}))*\}"
|
47 |
+
json_match = re.search(pattern, result)
|
48 |
+
if json_match:
|
49 |
+
conversation=json_match.group()
|
50 |
+
else:
|
51 |
+
conversation = template
|
52 |
speed = 1.0
|
53 |
models = {
|
54 |
"EN": TTS(language="EN", device=device),
|
|
|
56 |
speakers = ["EN-Default", "EN-US"]
|
57 |
|
58 |
combined_audio = AudioSegment.empty()
|
59 |
+
conversation = json.loads(conversation)
|
60 |
for i, turn in enumerate(conversation["conversation"]):
|
61 |
bio = io.BytesIO()
|
62 |
text = turn["text"]
|
|
|
84 |
aud = gr.Audio(interactive=False)
|
85 |
btn.click(synthesize, inputs=[text], outputs=[aud])
|
86 |
|
87 |
+
demo.queue(api_open=True, default_concurrency_limit=10).launch(show_api=True,share=True)
|
requirements.txt
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
gradio
|
2 |
spaces
|
|
|
3 |
tqdm
|
4 |
#torch
|
5 |
torchaudio
|
|
|
1 |
gradio
|
2 |
spaces
|
3 |
+
gradio_client
|
4 |
tqdm
|
5 |
#torch
|
6 |
torchaudio
|