Skip to content

Commit

Permalink
Expose model options and prompt tuning in the app
Browse files Browse the repository at this point in the history
  • Loading branch information
daavoo committed Nov 21, 2024
1 parent 06627fa commit 4457813
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
41 changes: 32 additions & 9 deletions demo/app.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from pathlib import Path

import streamlit as st
from huggingface_hub import list_repo_files

from opennotebookllm.preprocessing import DATA_LOADERS, DATA_CLEANERS
from opennotebookllm.text_to_podcast import load_model
from opennotebookllm.text_to_podcast import text_to_podcast

PODCAST_PROMPT = """
Convert this text into a podcast script.
The conversation should be between 2 speakers.
Use [SPEAKER1] and [SPEAKER2] to limit sections.
Do not include [INTRO], [OUTRO] or any other [SECTION].
Text:
"""

REPO = "allenai/OLMoE-1B-7B-0924-Instruct-GGUF"

uploaded_file = st.file_uploader(
"Choose a file", type=["pdf", "html", "txt", "docx", "md"]
Expand Down Expand Up @@ -33,13 +43,26 @@
)
clean_text = clean_text[: 4096 * 3]

with st.spinner("Downloading and Loading Model..."):
model = load_model()
model_name = st.selectbox("Select Model",
[
x for x in list_repo_files(REPO)
if ".gguf" in x
# The float16 is too big for the 16GB RAM codespace
and "f16" not in x
],
index=None
)
if model_name:
with st.spinner("Downloading and Loading Model..."):
model = load_model(model_id=f"{REPO}/{model_name}")

system_prompt = st.text_area("Podcast generation prompt", value=PODCAST_PROMPT)

with st.spinner("Writing Podcast Script..."):
text = ""
for chunk in text_to_podcast(clean_text, model, stream=True):
text += chunk
if text.endswith("\n"):
st.write(text)
text = ""
if st.button("Generate Podcast Script"):
with st.spinner("Generating Podcast Script..."):
text = ""
for chunk in text_to_podcast(clean_text, model, system_prompt=system_prompt, stream=True):
text += chunk
if text.endswith("\n"):
st.write(text)
text = ""
11 changes: 2 additions & 9 deletions src/opennotebookllm/text_to_podcast/inference.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from llama_cpp import Llama

PROMPT = """
Convert this text into a podcast script.
The conversation should be between 2 speakers.
Use [SPEAKER1] and [SPEAKER2] to limit sections.
Do not include [INTRO], [OUTRO] or any other [SECTION].
Text:
"""


def load_model(
model_id: str = "allenai/OLMoE-1B-7B-0924-Instruct-GGUF/olmoe-1b-7b-0924-instruct-q8_0.gguf",
):
) -> Llama:
org, repo, filename = model_id.split("/")
model = Llama.from_pretrained(
repo_id=f"{org}/{repo}",
Expand All @@ -23,7 +16,7 @@ def load_model(


def text_to_podcast(
input_text: str, model: Llama, system_prompt: str = PROMPT, stream: bool = False
input_text: str, model: Llama, system_prompt: str, stream: bool = False
):
response = model.create_chat_completion(
messages=[
Expand Down

0 comments on commit 4457813

Please sign in to comment.