import gradio as gr
from openai import OpenAI
import tempfile
import time
import typing as tp
from pathlib import Path
from pydub import AudioSegment
from dotenv import load_dotenv
load_dotenv()
client = OpenAI()
class FileCleaner:
def __init__(self, file_lifetime: float = 3600):
self.file_lifetime = file_lifetime
self.files = []
def add(self, path: tp.Union[str, Path]):
self._cleanup()
self.files.append((time.time(), Path(path)))
def _cleanup(self):
now = time.time()
for time_added, path in list(self.files):
if now - time_added > self.file_lifetime:
if path.exists():
path.unlink()
self.files.pop(0)
else:
break
file_cleaner = FileCleaner()
intro = AudioSegment.from_mp3("intro.mp3")
DEFAULT_SYSTEM_PROMPT = """
You are a podcast editor that specialized to create a script out of a webpage.
[TASKS]
- You will receive a link to a webpage about some content.
- You will create a script out of the content.
- The script should be 1 minute long if you read it out loud.
- Start with an intro to peak the interest of the listener.
- Then, summarize the content in a way that is easy to understand. Ask questions about the the content and answer them.
- Conclude with the most intriguing part of the content.
- Refrain from adding section headers in the script like [INTRUCTION], [CONTENT], [CONCLUSION].
- The script should be inspiring, written in colloquialism with english words and proverbs understood around the world.
- Write in a relax tone.
- Use filler words like 'um', 'ah', 'well' etc. to make it sound more natural.
[BREAKS]
- Use the