Spaces:
Paused
Paused
| import aiohttp.web, asyncio, urllib.parse, pathlib, builtins, numpy, PIL.Image, io, sys, math, os, uvloop, bs4, lxml, re, json, av, itertools, fake_useragent, huggingface_hub, time, traceback | |
| # use chatgpt to create narration say limit to 35 to 40 english words | |
| scripts = [ | |
| # Chapter 1 | |
| { | |
| "narration": "Protesters gathered in the capital, waving banners demanding Trump step down. Flames rose from makeshift barricades, and shouting filled the streets as the first clashes with law enforcement erupted, igniting nationwide unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Capital streets filled with protesters waving banners, flames rising from barricades, shouting, smoke drifting in the air, crowd pushing forward, dynamic urban environment." | |
| }, | |
| { | |
| "narration": "Thousands of demonstrators blocked major intersections, waving signs and chanting slogans. Fires illuminated buildings, and smoke curled into the sky as the crowd grew, drawing attention to the escalating movement against Trump.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Demonstrators crowd city intersections, holding banners, flames glowing, smoke rising, people moving, shouting slogans, urban streets filled with tension and energy." | |
| }, | |
| { | |
| "narration": "Crowds surged through streets, holding flags and placards high, while occasional fires lit the surroundings. Police attempted to contain the gathering, but clashes continued, signaling the start of a nationwide series of anti-Trump demonstrations.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Protesters marching with banners and flags, small fires burning, smoke drifting, crowd pushing forward, clashes spreading through urban streets, public space filled with action." | |
| }, | |
| { | |
| "narration": "The first confrontations with law enforcement escalated as protesters set ablaze objects and waved slogans demanding Trump resign. Smoke rose into the sky, the streets filled with shouting, marking the beginning of widespread demonstrations.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets with protesters holding banners, flames and smoke rising, crowd chanting, objects ablaze, street scenes filled with movement and public unrest." | |
| }, | |
| { | |
| "narration": "Early protests ignited in the heart of the capital, demonstrators waving placards and shouting slogans. Fires from barricades illuminated the streets, while law enforcement attempted to control the crowd, sparking a wave of nationwide activism.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Capital streets with protesters holding signs, flames and smoke rising from barricades, crowds shouting and moving, urban background filled with public activism." | |
| }, | |
| { | |
| "narration": "Protesters flooded the streets, carrying banners and signs calling for Trump to step down. Small fires broke out on roadblocks, smoke rising above the crowd, signaling the start of a larger, nationwide wave of demonstrations.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets crowded with protesters, banners waving, fires and smoke rising, people shouting, crowds pushing forward, background filled with city buildings." | |
| }, | |
| { | |
| "narration": "Demonstrators began blocking central avenues, holding banners and chanting, with small fires glowing along barricades. Smoke drifted through the streets as the protests grew larger, igniting public unrest across multiple cities.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Protesters waving banners, fires glowing along barricades, smoke drifting, crowd movement, urban streets crowded with people and flames, active street scene." | |
| }, | |
| { | |
| "narration": "The capital streets saw protesters waving signs and flags, setting makeshift fires along the road. Shouts and chants echoed as the crowd expanded, marking the beginning of widespread anti-Trump demonstrations throughout the country.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets crowded with protesters waving banners and flags, small fires along roads, smoke rising, people chanting, urban buildings in background." | |
| }, | |
| { | |
| "narration": "Protests ignited as thousands gathered in the capital, holding banners and lighting small fires. Smoke rose into the sky, crowds shouted slogans, and confrontations began with authorities, signaling the start of nationwide anti-Trump unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Capital streets with dense crowds holding banners, small fires burning, smoke rising, people shouting, urban environment filled with protest activity." | |
| }, | |
| { | |
| "narration": "Demonstrators surged into central streets, waving placards and chanting slogans against Trump. Makeshift barricades caught fire, smoke spiraled into the sky, and the crowd’s energy indicated the emergence of large-scale nationwide protests.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets filled with protesters waving banners, fires along barricades, smoke drifting, crowd pushing forward, urban buildings forming the backdrop." | |
| }, | |
| # chapter 2 | |
| { | |
| "narration": "Protesters flooded central city streets, waving banners and flags. Police tried to contain the crowd, but clashes intensified. Flames illuminated the roads, smoke filled the air, and people pushed against barricades, escalating tensions nationwide.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets filled with protesters holding banners and flags, small fires burning, smoke rising, people pushing against barricades, street crowded and tense." | |
| }, | |
| { | |
| "narration": "Demonstrators engaged in physical confrontations with law enforcement, shouting slogans and holding signs high. Fires lit nearby buildings, smoke rose into the sky, and the growing crowd continued pushing forward, heightening nationwide unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Crowded urban streets with protesters holding banners, fires illuminating buildings, smoke rising, people pushing forward, public unrest escalating." | |
| }, | |
| { | |
| "narration": "The crowd spread across main avenues, holding banners and flags. Occasional fires burned along barricades as smoke drifted upward. Police struggled to maintain order, while the expanding protests signaled escalating nationwide tension.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Protesters marching with banners and flags, fires along barricades, smoke drifting, people pushing forward, streets filled with tension and chaos." | |
| }, | |
| { | |
| "narration": "Street clashes intensified as protesters continued waving signs and shouting. Fires lit up barriers, smoke rose thickly, and pushing matches broke out among the crowd, signaling the spread of anti-Trump protests to multiple neighborhoods.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets crowded with protesters waving banners, small fires on barricades, smoke rising, people pushing, urban streets filled with unrest and flames." | |
| }, | |
| { | |
| "narration": "Protesters blocked intersections and clashed with police, holding banners high. Fires along streets emitted smoke into the sky, and the crowd pressed forward, demonstrating growing defiance and escalating the anti-Trump movement nationwide.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Crowded streets with protesters holding banners, flames along barricades, smoke rising, people pushing forward, urban environment filled with tension." | |
| }, | |
| { | |
| "narration": "The demonstrations spread into major city streets, banners waving and fires burning. Smoke filled the urban air as confrontations with authorities escalated, pushing protests into larger areas and intensifying public unrest nationwide.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets with protesters holding banners, fires burning along barricades, smoke drifting upward, crowd pushing, streets full of urban protest activity." | |
| }, | |
| { | |
| "narration": "Protesters surged forward, holding signs and flags. Occasional fires and thick smoke filled the streets. Clashes with police continued, demonstrating growing unrest and escalating nationwide anti-Trump demonstrations across multiple neighborhoods.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Protesters in urban streets with banners and flags, fires along barricades, smoke rising, people pushing forward, streets filled with conflict." | |
| }, | |
| { | |
| "narration": "Crowds expanded through central avenues, shouting slogans and holding banners high. Fires along barricades produced smoke that drifted across streets, while police struggled to control the surge, signaling escalation of nationwide protests.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets crowded with protesters waving banners, small fires along barricades, smoke rising, people pushing forward, urban area filled with tension." | |
| }, | |
| { | |
| "narration": "Street protests intensified, with demonstrators holding flags and banners while confronting law enforcement. Fires along barricades glowed, smoke rose into the sky, and pushing and shoving spread through the growing crowd nationwide.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets filled with protesters holding banners, fires burning, smoke drifting, people pushing and shoving, urban scene crowded and tense." | |
| }, | |
| { | |
| "narration": "Clashes escalated as thousands of protesters held banners and waved flags. Fires flared along roadblocks, smoke rose thickly, and the crowd pushed forward, turning local demonstrations into a nationwide surge of anti-Trump unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets with dense crowds holding banners and flags, fires burning along roadblocks, smoke rising, people pushing, protest activity escalating." | |
| }, | |
| #chapter 3 | |
| { | |
| "narration": "Protests spread to cities across the country, with thousands holding banners and flags. Fires flared along barricades, smoke rose into the sky, and confrontations with authorities intensified, demonstrating a nationwide surge of anti-Trump demonstrations.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets in multiple cities filled with protesters waving banners, small fires along barricades, smoke drifting upward, crowd pushing forward, urban areas showing large-scale unrest." | |
| }, | |
| { | |
| "narration": "Demonstrators flooded downtown streets nationwide, chanting slogans and holding signs. Fire from barricades illuminated surrounding buildings, smoke rose thickly, and large crowds pressed forward, showing the expansion of anti-Trump protests across multiple cities.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets filled with protesters waving banners and flags, fires burning along barricades, smoke drifting, people pushing forward, cityscape filled with protest activity." | |
| }, | |
| { | |
| "narration": "Crowds gathered in major cities, holding banners high and chanting slogans against Trump. Small fires burned along streets, smoke filled the air, and confrontations with law enforcement spread, indicating the nationwide reach of the demonstrations.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets crowded with protesters holding banners and flags, small fires along roads, smoke rising, people pushing forward, urban landscape filled with public unrest." | |
| }, | |
| { | |
| "narration": "Anti-Trump demonstrations erupted across multiple cities, protesters waving flags and signs. Fires lit temporary barricades, smoke rose above streets, and confrontations with authorities continued, marking the escalation from local to nationwide protests.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets crowded with protesters holding banners, fires on barricades, smoke rising, people pushing, urban areas filled with large-scale protest activity." | |
| }, | |
| { | |
| "narration": "Nationwide, demonstrators filled streets holding placards and flags, chanting slogans. Fires burned along roadblocks, smoke filled the air, and pushing spread through the crowd, signaling the large-scale spread of anti-Trump demonstrations across cities.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Multiple cities’ streets crowded with protesters, banners waving, fires along barricades, smoke rising, crowd pushing forward, urban environment showing unrest." | |
| }, | |
| { | |
| "narration": "Protests expanded beyond the capital, with thousands taking to streets nationwide. Fire flared along barricades, smoke drifted above the crowd, and demonstrators pressed forward, signaling the growing scale and intensity of the anti-Trump movement.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets nationwide filled with protesters holding banners and flags, fires burning along barricades, smoke rising, people pushing forward, urban areas full of protest activity." | |
| }, | |
| { | |
| "narration": "Demonstrators crowded streets in multiple cities, holding banners and chanting slogans. Small fires lit the barricades, smoke rose into the air, and confrontations with law enforcement escalated, reflecting the nationwide spread of the protests.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets in several cities filled with protesters waving banners, fires burning along barricades, smoke drifting, crowd pushing forward, urban areas full of unrest." | |
| }, | |
| { | |
| "narration": "Nationwide, streets were filled with protesters holding flags and banners. Fires along barricades glowed, smoke rose into the sky, and pushing spread through the crowd, marking the escalation and spread of anti-Trump demonstrations across the country.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets filled with protesters waving banners, fires along barricades, smoke rising, people pushing forward, urban areas filled with protest activity." | |
| }, | |
| { | |
| "narration": "Crowds gathered in urban centers nationwide, chanting slogans and holding placards. Fires flared along barricades, smoke drifted across streets, and confrontations continued, showing the anti-Trump protests had expanded to a large national scale.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets nationwide crowded with protesters waving banners and flags, fires along barricades, smoke drifting, crowd pushing forward, streets full of unrest." | |
| }, | |
| { | |
| "narration": "Protests swept across cities nationwide, with thousands holding banners and chanting slogans. Fires burned along makeshift barricades, smoke rose high, and confrontations with authorities persisted, illustrating the national expansion of anti-Trump demonstrations.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Multiple city streets filled with protesters holding banners, fires along barricades, smoke rising, people pushing forward, urban areas showing widespread unrest." | |
| }, | |
| #chapter 4 | |
| { | |
| "narration": "Amid nationwide protests, Trump issued a statement defending his position and criticizing the demonstrators. Crowds continued chanting and waving banners across multiple cities, while smoke from barricades rose, showing tensions remained high.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets filled with protesters waving banners and flags, small fires along barricades, smoke rising, people shouting, cityscape filled with ongoing public unrest." | |
| }, | |
| { | |
| "narration": "Trump addressed the unrest in a public statement, rejecting calls to resign. Meanwhile, protesters held signs and chanted slogans in multiple cities, with flames from barricades and rising smoke highlighting the escalating nationwide demonstrations.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets crowded with protesters waving banners and signs, fires burning along barricades, smoke drifting, people pushing forward, urban areas full of protest activity." | |
| }, | |
| { | |
| "narration": "As protests intensified, Trump released remarks defending his administration and condemning the riots. Demonstrators pressed forward in streets nationwide, holding banners high, while small fires and smoke signaled escalating clashes and unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets filled with protesters waving banners and flags, fires burning along barricades, smoke rising, crowd pushing forward, urban environment full of public protest." | |
| }, | |
| { | |
| "narration": "Trump’s statement aimed to downplay the unrest, asserting authority and questioning the protests. Yet, demonstrators continued chanting in cities across the country, with fires and smoke along barricades underscoring the tension and scale of the movement.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets crowded with protesters waving banners, fires along barricades, smoke rising, people pushing forward, city filled with protest activity." | |
| }, | |
| { | |
| "narration": "Despite Trump’s defense and criticism of demonstrators, protests surged. Thousands held banners and signs across city streets, flames from barricades illuminated the crowds, and smoke rose high, indicating that nationwide unrest remained intense.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets filled with protesters waving banners and signs, small fires along barricades, smoke rising, people pushing forward, urban areas crowded with unrest." | |
| }, | |
| { | |
| "narration": "Trump’s public remarks sought to justify his position while protests continued in multiple cities. Demonstrators held banners and chanted slogans, with small fires burning along barricades, smoke filling the streets and unrest spreading nationwide.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets filled with protesters holding banners and flags, small fires burning, smoke rising, people pushing forward, cityscape full of protest activity." | |
| }, | |
| { | |
| "narration": "As protests escalated nationwide, Trump released statements defending his administration and criticizing demonstrators. Fires along barricades and rising smoke filled city streets, while crowds of protesters pressed forward with banners and chants.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets crowded with protesters waving banners, fires burning along barricades, smoke drifting upward, people pushing forward, urban environment full of unrest." | |
| }, | |
| { | |
| "narration": "Trump’s comments did little to quell unrest, as protesters continued chanting slogans and holding banners. Flames along barricades and smoke rising into the sky highlighted ongoing confrontations across multiple cities nationwide.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets filled with protesters holding banners and flags, fires burning along barricades, smoke rising, crowd pushing forward, cityscape showing public unrest." | |
| }, | |
| { | |
| "narration": "Despite Trump’s public defense, anti-Trump demonstrations expanded. Protesters marched through city streets with banners and flags, fires along barricades burned, and smoke rose, signaling ongoing tension and widespread nationwide unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets crowded with protesters waving banners, fires along barricades, smoke rising, people pushing forward, urban areas filled with active demonstrations." | |
| }, | |
| { | |
| "narration": "Trump addressed the protests, defending his administration and denouncing demonstrators. Yet, protesters persisted in chanting and holding signs, with fires along streets and smoke rising, illustrating the nationwide spread and intensity of unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets filled with protesters waving banners, fires along barricades, smoke drifting upward, crowd pushing forward, city filled with anti-Trump demonstrations." | |
| }, | |
| #chapter 5 | |
| { | |
| "narration": "Public opinion divided as protests continued across cities. Supporters and opponents of Trump voiced their views, while fires and smoke from barricades filled streets. Nationwide discussions intensified, and the anti-Trump movement remained a central political issue.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets crowded with protesters holding banners, small fires along barricades, smoke rising, people shouting, city filled with ongoing debate and nationwide political tension." | |
| }, | |
| { | |
| "narration": "As nationwide demonstrations persisted, citizens voiced opinions for and against Trump. Street barricades burned, smoke filled the air, and crowds continued chanting slogans, highlighting ongoing debates and deep divisions across the country.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets filled with protesters waving banners, fires along barricades, smoke rising, people shouting slogans, urban environment showing political unrest and public divisions." | |
| }, | |
| { | |
| "narration": "The anti-Trump movement remained strong, with demonstrations and public debate spreading across cities. Fires along barricades emitted smoke, crowds held banners, and citizens expressed conflicting opinions, emphasizing the nationwide political tension and unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets crowded with protesters holding banners, small fires burning along barricades, smoke drifting upward, people pushing forward, cityscape reflecting political unrest." | |
| }, | |
| { | |
| "narration": "Public debates intensified as protests persisted. Crowds carried banners and chanted slogans, fires along barricades burned, and smoke rose into city streets. Supporters and opponents of Trump engaged in widespread discussion, illustrating the ongoing national divide.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets crowded with protesters waving banners, fires along barricades, smoke rising, people pushing and chanting, urban areas filled with political unrest." | |
| }, | |
| { | |
| "narration": "Citizens across cities voiced differing opinions on Trump amid continued protests. Barricade fires glowed, smoke drifted through streets, and demonstrators carried banners while shouting slogans, signaling ongoing nationwide debate and heightened public attention.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets filled with protesters holding banners, small fires along barricades, smoke rising, people shouting, city crowded with public debate and tension." | |
| }, | |
| { | |
| "narration": "The nationwide anti-Trump movement continued, with citizens holding banners and expressing views. Fires along barricades and smoke rising into streets emphasized ongoing unrest, while public debate and discussion about Trump’s leadership persisted across cities.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets crowded with protesters waving banners, fires along barricades, smoke rising, people shouting, urban environment filled with political tension and public discourse." | |
| }, | |
| { | |
| "narration": "Protests persisted as citizens voiced opposing opinions about Trump. Barricades burned with small fires, smoke filled the air, and demonstrators chanted slogans, highlighting continuing nationwide debate and the strength of the anti-Trump movement.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets crowded with protesters waving banners, small fires along barricades, smoke rising, people chanting, city filled with ongoing political unrest." | |
| }, | |
| { | |
| "narration": "The anti-Trump protests remained widespread, with banners, flames, and smoke in city streets. Citizens expressed differing opinions while chanting, emphasizing national debates, ongoing unrest, and the movement’s significance in the political landscape.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. City streets filled with protesters holding banners, small fires along barricades, smoke rising, people shouting slogans, urban environment showing large-scale political tension." | |
| }, | |
| { | |
| "narration": "Nationwide demonstrations continued, with citizens holding banners and expressing diverse views. Fires along barricades and rising smoke filled streets, while discussions about Trump’s leadership intensified, reflecting ongoing political division and public engagement.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Urban streets crowded with protesters waving banners, fires burning along barricades, smoke rising, people shouting, city filled with political debate and unrest." | |
| }, | |
| { | |
| "narration": "Protests persisted across cities as citizens voiced support and opposition to Trump. Barricade fires burned, smoke rose into streets, and demonstrators carried banners and shouted slogans, showing ongoing national debate and the continued intensity of unrest.", | |
| "prompt": "White day, sunlight, soft light, mid-shot, warm tone, center composition. Streets filled with protesters holding banners, small fires along barricades, smoke rising, people chanting, urban areas crowded with ongoing anti-Trump demonstrations." | |
| } | |
| ][:2] | |
| negative = 'Bright tones, overexposed, static, blurry details, subtitles, style, work, painting, picture, still, overall grayish, worst quality, low quality, JPEG compression residue, ugly, incomplete, redundant fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, deformed limbs, finger fusion, still picture A messy background, three legs, a lot of people in the background, walking backwards' | |
| speak = lxml.etree.Element('speak', nsmap={None:'http://www.w3.org/2001/10/synthesis', 'mstts':'http://www.w3.org/2001/mstts'}, attrib={'{http://www.w3.org/XML/1998/namespace}lang':'en-US', 'version':'1.0'}) | |
| voice = lxml.etree.SubElement(speak, 'voice', attrib={'name':'en-US-AriaNeural'}) | |
| async def bing(prompt): | |
| voice.text = prompt | |
| async with aiohttp.ClientSession(headers={'user-agent':fake_useragent.UserAgent().chrome}) as session: | |
| async with session.get('https://www.bing.com/translator', params={'from':'en-US'}) as translator: | |
| html = bs4.BeautifulSoup(await translator.text(), 'lxml') | |
| params_AbusePreventionHelper = json.loads(builtins.next(_ for _ in builtins.str(html.find('script', string=re.compile('var params_AbusePreventionHelper =')).string).split(';') if _.startswith(' var params_AbusePreventionHelper =')).split(' = ')[1]) | |
| async with session.post('https://www.bing.com/tfettts', params={'isVertical':1, 'IG':builtins.next(_ for _ in builtins.str(html.find('script', string=re.compile('IG:')).string).split(',') if _.startswith('IG:')).split('"')[1], 'IID':html.find('div', attrs={'id':'rich_tta'}).get('data-iid')}, data={'ssml':lxml.etree.tostring(speak, encoding='UTF-8').decode(), 'token':params_AbusePreventionHelper[1], 'key':params_AbusePreventionHelper[0]}) as tfettts: return await tfettts.content.read() | |
| async def google(prompt): | |
| async with aiohttp.ClientSession(headers={'user-agent':fake_useragent.UserAgent().chrome}) as session: | |
| async with session.get('https://translate.google.com/translate_tts', params={'ie':'UTF-8', 'q':prompt, 'tl':'en', 'client':'tw-ob'}) as translate_tts: return await translate_tts.content.read() | |
| async def pollinations(prompt): | |
| async with aiohttp.ClientSession() as session: #https://auth.pollinations.ai #https://github.com/pollinations/pollinations/blob/main/APIDOCS.md | |
| async with session.get(f'https://text.pollinations.ai/{urllib.parse.quote(prompt)}', params={'model':'openai-audio', 'voice':'alloy'}, headers={'authorization':'Bearer ' + os.getenv('pollinations')}) as tts: return await tts.content.read() | |
| async def main(): | |
| app = aiohttp.web.Application() | |
| app.add_routes([aiohttp.web.static('/', pathlib.Path(__file__).resolve().parent, show_index=True)]) | |
| runner = aiohttp.web.AppRunner(app) | |
| await runner.setup() | |
| site = aiohttp.web.TCPSite(runner, port=7860) | |
| await site.start() | |
| async with aiohttp.ClientSession(headers={'authorization':'Bearer ' + os.getenv('modelscope')}, timeout=aiohttp.ClientTimeout()) as client: | |
| async with client.post('https://chaowenguo-qwen.ms.show/start', json={'prompt':scripts[0].get('prompt'), 'height':720, 'width':1280}) as _:pass | |
| while True: | |
| async with client.get('https://chaowenguo-qwen.ms.show/get') as qwen: | |
| print(qwen.status) | |
| if qwen.status == 404: await asyncio.sleep(60) | |
| else: | |
| buffer = io.BytesIO(await qwen.content.read()) | |
| image = PIL.Image.open(buffer) | |
| with av.open('output.mp4', mode='w') as writer: | |
| video = writer.add_stream('h264', rate=8) | |
| video.height = image.size[1] | |
| video.width = image.size[0] | |
| video.pix_fmt = 'yuv420p' | |
| videoPts = 0 | |
| audioPts = 0 | |
| audio = None | |
| for script in scripts: | |
| outer = False | |
| while True: | |
| with aiohttp.MultipartWriter('form-data') as mpwriter: | |
| mpwriter.append(script.get('prompt')).set_content_disposition('form-data', name='prompt') | |
| mpwriter.append(negative).set_content_disposition('form-data', name='negative') | |
| mpwriter.append(buffer.getvalue(), {'Content-Type':'image/png'}).set_content_disposition('form-data', name='image', filename='image.png') | |
| tail = 'https://chaowenguo-en.ms.show/' | |
| async with client.post(urllib.parse.urljoin(tail, 'start'), data=mpwriter) as _: pass | |
| while True: | |
| try: | |
| async with client.get(urllib.parse.urljoin(tail, 'get')) as get: | |
| print(get.status) | |
| match get.status: | |
| case 404: await asyncio.sleep(60) | |
| case 500 | 429: break | |
| case 200: | |
| reader = numpy.load(io.BytesIO(await get.content.read())).get('arr_0') | |
| buffer.seek(0) | |
| buffer.truncate(0) | |
| PIL.Image.fromarray(reader[-1]).save(buffer, format='png') | |
| with av.open(io.BytesIO(await sys.modules.get(__name__).pollinations(script.get('narration'))), format='mp3') as container: | |
| if not audio: audio = writer.add_stream('aac', rate=container.streams.audio[0].rate) | |
| speed = builtins.float(container.streams.audio[0].duration * container.streams.audio[0].time_base) / 10 | |
| print(speed) | |
| graph = av.filter.Graph() | |
| graph.link_nodes(graph.add_abuffer(template=container.streams.audio[0]), graph.add('atempo', builtins.str(speed)), graph.add('apad', 'whole_dur=10'), graph.add('atrim', '0:10'), graph.add('abuffersink')).configure() | |
| for frame in container.decode(): | |
| frame.pts = audioPts | |
| audioPts += frame.samples | |
| graph.push(frame) | |
| while True: | |
| try: writer.mux(audio.encode(graph.pull())) | |
| except (av.BlockingIOError, av.EOFError): break | |
| graph = av.filter.Graph() | |
| pathlib.Path(__file__).resolve().parent.joinpath('subtitle.ass').write_text(pathlib.Path(__file__).resolve().parent.joinpath('subtitle').read_text().replace('prompt', script.get('narration'))) | |
| graph.link_nodes(graph.add_buffer(height=video.height, width=video.width, format='rgb24', time_base=video.time_base), graph.add('subtitles', 'subtitle.ass'), graph.add('buffersink')).configure() | |
| for _ in itertools.islice(reader, reader.shape[0] - 1): | |
| frame = av.VideoFrame.from_ndarray(_) | |
| frame.pts = videoPts | |
| videoPts += video.time_base.denominator // video.average_rate | |
| graph.push(frame) | |
| while True: | |
| try: writer.mux(video.encode(graph.pull())) | |
| except (av.BlockingIOError, av.EOFError):break | |
| graph.push(None) | |
| while True: | |
| try: writer.mux(video.encode(graph.pull())) | |
| except (av.BlockingIOError, av.EOFError):break | |
| outer = True | |
| break | |
| except (aiohttp.ClientConnectionError, aiohttp.ClientPayloadError): break | |
| if outer: break | |
| writer.mux(video.encode()) | |
| writer.mux(audio.encode()) | |
| break | |
| huggingface_hub.upload_file(path_or_fileobj='output.mp4', path_in_repo='en.mp4', repo_id='chaowenguoback/wan', repo_type='dataset', token=os.getenv('huggingface')) | |
| await asyncio.sleep(math.inf) | |
| try: | |
| uvloop.run(main()) | |
| except: | |
| pathlib.Path(__file__).resolve().parent.joinpath('en.txt').write_text(traceback.format_exc()) | |
| huggingface_hub.upload_file(path_or_fileobj='en.txt', path_in_repo='en.txt', repo_id='chaowenguoback/wan', repo_type='dataset', token=os.getenv('huggingface')) | |
| time.sleep(math.inf) |