Spaces:
Sleeping
Sleeping
from dotenv import load_dotenv | |
from openai import OpenAI | |
import streamlit as st | |
load_dotenv() | |
st.write('## This is an example to show summarization') | |
examples = { | |
"example 1": """Boston's injury reporting for Kristaps Porzi艈模is has been fairly coy. He missed Game 3, but his coach told reporters just before Game 4 that was technically available, but with a catch. | |
Joe Mazzulla said Porzi艈模is would "only be used in specific instances, if necessary." That sounds like the team doesn't want to risk further injury to his dislocated Posterior Tibialis (or some other body part, due to overcompensation for the ankle), unless it's in a desperate situation. | |
Being up 3-1, with Game 5 at home, doesn't qualify as desperate. So, expect the Celtics to continue slow-playing KP's return. | |
It'd obviously be nice for Boston to have his rim protection and jump shooting back. It was missed in the Game 4 blowout, but the Celtics have also demonstrated they can win without the big man throughout this campaign. | |
On top of winning Game 3 of this series, Boston is plus-10.9 points per 100 possessions when Porzi艈模is has been off the floor this regular and postseason.""", | |
"example 2": """Prior to the Finals, we predicted that Dereck Lively II's minutes would swell over the course of the series, and that's starting to play out. | |
He averaged 18.8 minutes in Games 1 and 2 and was up to 26.2 in Games 3 and 4. That's with the regulars being pulled long before the final buzzer in Friday's game, too. | |
Expect the rookie's playing time to continue to climb in Game 5. It seems increasingly clear that coach Jason Kidd trusts him over the rest of Dallas' bigs, and it's not hard to see why. | |
Lively has been absolutely relentless on the offensive glass all postseason. He makes solid decisions as a passer when his rolls don't immediately lead to dunks. And he's not a liability when caught defending guards or wings outside. | |
All of that has led to postseason averages of 8.2 points, 7.6 rebounds, 1.4 assists and 1.0 blocks in just 21.9 minutes, as well as a double-double in 22 minutes of Game 4. | |
Back in Boston, Kidd is going to rely on Lively even more. He'll play close to 30 minutes and reach double-figures in both scoring and rebounding again.""", | |
} | |
def generate_answer(lm, sources, model_name="gpt-4o"): # noqa: ANN201, ANN001 | |
meta_prompt = """ | |
{sources} | |
summarization: """ # noqa: E501 | |
content = meta_prompt.format( | |
sources=sources, | |
) | |
answer = lm.chat.completions.create( | |
temperature=0.8, | |
max_tokens=800, | |
messages=[ | |
{ | |
"role": "user", | |
"content": content, | |
}, | |
], | |
model=model_name, | |
) | |
return answer | |
example_selection = st.selectbox("Choose an example", options=list(examples.keys()), index=0) | |
model_selection = st.selectbox("Choose a model", options=[ | |
"gpt-3.5-turbo", | |
"gpt-4o", | |
"gpt-4" | |
], index=0) | |
# Input fields | |
input_text1 = st.text_area("question", height=None, \ | |
placeholder="Enter first text here...", value=examples[example_selection]) | |
# Button to trigger processing | |
lm = OpenAI() | |
if st.button('Submit'): | |
if input_text1: | |
response = generate_answer(lm, input_text1, model_selection) | |
st.write('## Orginal Article:') | |
st.markdown(examples[example_selection]) | |
st.write('## Summarization:') | |
st.markdown(response.choices[0].message.content) | |
else: | |
# Show an error message if the required input is missing | |
st.error("Please fill both inputs to generate outputs.") | |