|
import gradio as gr |
|
import asyncio |
|
import copy |
|
import json |
|
import base64 |
|
from io import BytesIO |
|
import IPython.display as ipd |
|
from watchgod import awatch |
|
from Complete import ( |
|
Speak, |
|
Transcriber, |
|
MovieDescriptionProcessor, |
|
) |
|
|
|
tts_client = Speak() |
|
movie_processor = MovieDescriptionProcessor() |
|
|
|
|
|
|
|
def gradio_app(movie_name, year, media_type, original_language, go_button): |
|
if go_button: |
|
print("here") |
|
|
|
message = movie_processor.prompt_fetcher() |
|
message = message.format( |
|
media_type=media_type, |
|
movie_name=movie_name, |
|
original_language=original_language, |
|
movie_year=year, |
|
) |
|
|
|
|
|
script = asyncio.run(movie_processor.process_movie_description(message)) |
|
|
|
|
|
message, result = movie_processor.prompt_fetcher("images").split("{format}") |
|
message = message.format(script=script) + result |
|
images_descriptions = asyncio.run( |
|
movie_processor.process_movie_description(message, "Assistant") |
|
) |
|
image_json = movie_processor.extract_json_from_markdown(images_descriptions) |
|
|
|
|
|
audio_file_path = asyncio.run(tts_client.say(script)) |
|
|
|
|
|
transcriber = Transcriber(audio_file_path) |
|
|
|
|
|
asyncio.run(transcriber.transcribe()) |
|
|
|
|
|
output_json_path = "./output.json" |
|
asyncio.run(transcriber.download_transcription(output_json_path)) |
|
|
|
|
|
return { |
|
"image_json": image_json, |
|
"audio_file": {"name": "audio_file.wav", "file_path": audio_file_path}, |
|
"tts_json": {"name": "tts_output.json", "file_path": output_json_path}, |
|
} |
|
return None |
|
|
|
|
|
|
|
inputs = [ |
|
gr.Textbox(placeholder="Avatar", label="Movie Name"), |
|
gr.Textbox(placeholder="2023", label="Year"), |
|
gr.Radio(choices=["movie", "tv series"], label="Media Type"), |
|
gr.Dropdown(choices=["English", "Spanish"], label="Original Language"), |
|
gr.Button("go_button"), |
|
] |
|
|
|
|
|
|
|
outputs = [ |
|
gr.Textbox("image_json", label="Image JSON"), |
|
|
|
|
|
] |
|
|
|
|
|
iface = gr.Interface(fn=gradio_app, inputs=inputs, outputs=outputs, live=True) |
|
|
|
|
|
|
|
async def restart_gradio(): |
|
async for changes in awatch(".", watcher_cls=watchgod.DefaultDirWatcher): |
|
await iface.close() |
|
iface.launch() |
|
|
|
|
|
|
|
loop = asyncio.get_event_loop() |
|
loop.create_task(restart_gradio()) |
|
iface.launch() |
|
|