Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
#Using codes from killerz3/PodGen & eswardivi/Podcastify
|
|
|
2 |
import json
|
3 |
-
import spaces
|
4 |
import httpx
|
5 |
import os
|
6 |
import re
|
@@ -9,9 +9,9 @@ import edge_tts
|
|
9 |
import torch
|
10 |
import tempfile
|
11 |
import gradio as gr
|
12 |
-
import
|
13 |
from pydub import AudioSegment
|
14 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
15 |
|
16 |
from moviepy.editor import AudioFileClip, concatenate_audioclips
|
17 |
|
@@ -52,16 +52,22 @@ footer {
|
|
52 |
}
|
53 |
"""
|
54 |
|
55 |
-
MODEL_ID = "01-ai/Yi-1.5-
|
|
|
56 |
|
|
|
|
|
|
|
57 |
model = AutoModelForCausalLM.from_pretrained(
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
).eval()
|
62 |
|
63 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
64 |
|
|
|
|
|
65 |
|
66 |
def validate_url(url):
|
67 |
try:
|
@@ -127,8 +133,9 @@ async def gen_show(script):
|
|
127 |
print(f"Deleted temporary file: {temp_file}")
|
128 |
|
129 |
return output_filename
|
130 |
-
|
131 |
-
|
|
|
132 |
def generator(messages):
|
133 |
input_ids = tokenizer.apply_chat_template(
|
134 |
conversation=messages,
|
@@ -148,6 +155,8 @@ def generator(messages):
|
|
148 |
results = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
|
149 |
print(results)
|
150 |
return results
|
|
|
|
|
151 |
|
152 |
def extract_content(text):
|
153 |
"""Extracts the JSON content from the given text."""
|
@@ -166,15 +175,22 @@ async def main(link):
|
|
166 |
if "Error" in text:
|
167 |
return text, None
|
168 |
|
169 |
-
prompt = f"News: {text}"
|
170 |
-
|
171 |
-
messages = [
|
172 |
-
|
173 |
-
|
174 |
-
]
|
175 |
-
|
176 |
-
generated_script = extract_content(generator(messages))
|
177 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
178 |
print("Generated Script:"+generated_script)
|
179 |
|
180 |
# Check if the generated_script is empty or not valid JSON
|
|
|
1 |
#Using codes from killerz3/PodGen & eswardivi/Podcastify
|
2 |
+
#For ZeroGPU limit, I roll back to inference API. You can use local or HF model also, remove the relative comment sign, it works;
|
3 |
import json
|
|
|
4 |
import httpx
|
5 |
import os
|
6 |
import re
|
|
|
9 |
import torch
|
10 |
import tempfile
|
11 |
import gradio as gr
|
12 |
+
from huggingface_hub import AsyncInferenceClient
|
13 |
from pydub import AudioSegment
|
14 |
+
#from transformers import AutoModelForCausalLM, AutoTokenizer
|
15 |
|
16 |
from moviepy.editor import AudioFileClip, concatenate_audioclips
|
17 |
|
|
|
52 |
}
|
53 |
"""
|
54 |
|
55 |
+
MODEL_ID = "01-ai/Yi-1.5-34B-Chat"
|
56 |
+
Client = AsyncInferenceClient(MODEL_ID)
|
57 |
|
58 |
+
|
59 |
+
"""
|
60 |
+
# USING LOCAL MODEL
|
61 |
model = AutoModelForCausalLM.from_pretrained(
|
62 |
+
MODEL_ID,
|
63 |
+
torch_dtype=torch.float16,
|
64 |
+
device_map="auto"
|
65 |
).eval()
|
66 |
|
67 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
|
68 |
|
69 |
+
"""
|
70 |
+
|
71 |
|
72 |
def validate_url(url):
|
73 |
try:
|
|
|
133 |
print(f"Deleted temporary file: {temp_file}")
|
134 |
|
135 |
return output_filename
|
136 |
+
|
137 |
+
"""
|
138 |
+
# USING LOCAL MODEL
|
139 |
def generator(messages):
|
140 |
input_ids = tokenizer.apply_chat_template(
|
141 |
conversation=messages,
|
|
|
155 |
results = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
|
156 |
print(results)
|
157 |
return results
|
158 |
+
"""
|
159 |
+
|
160 |
|
161 |
def extract_content(text):
|
162 |
"""Extracts the JSON content from the given text."""
|
|
|
175 |
if "Error" in text:
|
176 |
return text, None
|
177 |
|
178 |
+
prompt = f"News: {text} json:"
|
179 |
+
formatted_prompt = system_prompt + "\n\n\n" + text
|
180 |
+
# messages = [
|
181 |
+
# {"role": "system", "content": system_prompt},
|
182 |
+
# {"role": "user", "content": prompt},
|
183 |
+
# ]
|
|
|
|
|
184 |
|
185 |
+
answer = Client.text_generation(
|
186 |
+
prompt=formatted_prompt,
|
187 |
+
max_new_tokens=4096,
|
188 |
+
details=True,
|
189 |
+
temperature=0.7,
|
190 |
+
return_full_text=False)
|
191 |
+
print(answer)
|
192 |
+
#generated_script = extract_content(generator(messages))
|
193 |
+
generated_script = extract_content(answer)
|
194 |
print("Generated Script:"+generated_script)
|
195 |
|
196 |
# Check if the generated_script is empty or not valid JSON
|