Spaces:
Runtime error
Runtime error
File size: 1,406 Bytes
ccac9c6 ec912f3 25c3372 ec912f3 ccac9c6 3fae9c4 ccac9c6 25c3372 5572066 25c3372 c53e9f3 59ee795 ccac9c6 9e4163f d4f9919 ccac9c6 2e91337 ccac9c6 d4f9919 ccac9c6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
import pytube
from transformers import pipeline
from time import sleep
generator = pipeline('text-generation', model='parseny/youtube_comment_generation_model')
def generate(text):
yt = pytube.YouTube(text)
while True:
try:
title = yt.title
title = title.replace("[^a-zA-Z#]", " ")
title = title.replace(" +", " ")
title = title.lower()
prompt = f"Title: {title}\nComment:"
break
except:
sleep(1)
yt = pytube.YouTube(text)
continue
result = generator(prompt, max_new_tokens=30, pad_token_id=50256, num_return_sequences=1, do_sample=True)
return result[0]["generated_text"]
examples = [
["https://www.youtube.com/watch?v=mCV44C5rQ2M"],
["https://www.youtube.com/watch?v=sitXeGjm4Mc"],
["https://www.youtube.com/watch?v=oQS8KUoWL8E"],
]
# input_textbox = gr.inputs.Textbox(lines=5, label="Input Text")
# output_textbox = gr.outputs.Textbox(label="Generated Text")
demo = gr.Interface(
fn=generate,
inputs=gr.Textbox(lines=5, label="Input Text"),
outputs=gr.Textbox(label="Generated Text"),
examples=examples
)
# demo = gr.Interface(
# fn=generate,
# inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
# outputs=gr.outputs.Textbox(label="Generated Text"),
# examples=examples
# )
demo.launch() |