Skip to content

Commit

Permalink
replace gemini with gpt 4o-mini
Browse files Browse the repository at this point in the history
  • Loading branch information
knowsuchagency committed Jul 20, 2024
1 parent 023ae3c commit ccc321b
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,19 @@ def get_mp3(text: str, voice: str, api_key: str = None) -> bytes:
return file.getvalue()


def generate_audio(
file: str,
openai_api_key: str = None,
gemini_api_key: str = None,
) -> bytes:
def generate_audio(file: str, openai_api_key: str = None) -> bytes:

if not os.getenv("OPENAI_API_KEY", openai_api_key):
raise gr.Error("OpenAI API key is required")

if not os.getenv("GEMINI_API_KEY", gemini_api_key):
raise gr.Error("Gemini API key is required")

with Path(file).open("rb") as f:
reader = PdfReader(f)
text = "\n\n".join([page.extract_text() for page in reader.pages])

@retry(retry=retry_if_exception_type(ValidationError))
@llm(model="gemini/gemini-1.5-flash", max_tokens=8192, api_key=gemini_api_key)
@llm(
model="gpt-4o-mini",
)
def generate_dialogue(text: str) -> Dialogue:
"""
Your task is to take the input text provided and turn it into an engaging, informative podcast dialogue. The input text may be messy or unstructured, as it could come from a variety of sources like PDFs or web pages. Don't worry about the formatting issues or any irrelevant information; your goal is to extract the key points and interesting facts that could be discussed in a podcast.
Expand Down Expand Up @@ -166,16 +161,12 @@ def generate_dialogue(text: str) -> Dialogue:
label="OpenAI API Key",
visible=not os.getenv("OPENAI_API_KEY"),
),
gr.Textbox(
label="Gemini API Key",
visible=not os.getenv("GEMINI_API_KEY"),
),
],
outputs=[
gr.Audio(label="Audio", format="mp3"),
gr.Textbox(label="Transcript"),
],
allow_flagging=False,
allow_flagging="never",
clear_btn=None,
head=os.getenv("HEAD", "") + Path("head.html").read_text(),
cache_examples="lazy",
Expand Down

0 comments on commit ccc321b

Please sign in to comment.