Spaces:
Sleeping
Sleeping
kz209
commited on
Commit
•
9a1ab03
1
Parent(s):
5922993
initialize
Browse files- README.md +50 -1
- app.py +18 -0
- pages/arena.py +21 -0
- pages/summarization_example.py +75 -0
- pyproject.toml +23 -0
- requirements.txt +2 -0
- utils/__init__.py +4 -0
- utils/__pycache__/__init__.cpython-311.pyc +0 -0
- utils/__pycache__/multiple_stream.cpython-311.pyc +0 -0
- utils/multiple_stream.py +35 -0
README.md
CHANGED
@@ -9,4 +9,53 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
# Chris Labs
|
13 |
+
|
14 |
+
## Description
|
15 |
+
|
16 |
+
A collection and display of projects from Chris's group.
|
17 |
+
|
18 |
+
## Installation
|
19 |
+
|
20 |
+
### Install `poetry` (if not already installed)
|
21 |
+
|
22 |
+
Check this [website](https://python-poetry.org/docs/) for installation instructions.
|
23 |
+
|
24 |
+
### Create a Cirtual Environment
|
25 |
+
|
26 |
+
Navigate to the main directory chris-labs and run the following commands to create a virtual environment:
|
27 |
+
|
28 |
+
```sh
|
29 |
+
python3 -m venv venv
|
30 |
+
source venv/bin/activate
|
31 |
+
```
|
32 |
+
|
33 |
+
### Install Dependency
|
34 |
+
|
35 |
+
Run the following command to install project dependencies:
|
36 |
+
|
37 |
+
```sh
|
38 |
+
poetry install
|
39 |
+
```
|
40 |
+
|
41 |
+
Change the `OPENAI_API_KEY` in `.env`
|
42 |
+
|
43 |
+
### Run `streamlit`
|
44 |
+
|
45 |
+
Start the Streamlit application by running:
|
46 |
+
|
47 |
+
```sh
|
48 |
+
streamlit run streamlit/home.py
|
49 |
+
```
|
50 |
+
|
51 |
+
Have Fun!
|
52 |
+
|
53 |
+
## How to Contribute
|
54 |
+
|
55 |
+
### Creating a Branch
|
56 |
+
|
57 |
+
Each member should create a branch with their own name and commit to that branch. To merge with main, open a pull request and request review.
|
58 |
+
|
59 |
+
### Bug Fixes and Questions
|
60 |
+
|
61 |
+
For bug fixes or questions, either open an issue or create a branch prefixed with `bug` in name.
|
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(
|
4 |
+
page_title="Summarization Projects Demo",
|
5 |
+
page_icon=":rocket:",
|
6 |
+
)
|
7 |
+
|
8 |
+
st.write("## Summarization Projects Demo :rocket:")
|
9 |
+
|
10 |
+
st.markdown(
|
11 |
+
"""
|
12 |
+
This application is for **internal use** and is designed to facilitate **fast prototyping** and **experimentation.**
|
13 |
+
|
14 |
+
👈 Select a demo from the sidebar to begin experimentation.
|
15 |
+
"""
|
16 |
+
)
|
17 |
+
|
18 |
+
st.sidebar.success("Select a demo above.")
|
pages/arena.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import sys
|
2 |
+
from concurrent.futures import ThreadPoolExecutor
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
from streamlit.runtime.scriptrunner.script_run_context import \
|
6 |
+
get_script_run_ctx
|
7 |
+
|
8 |
+
sys.path.append(".") # Add parent directory to Python path
|
9 |
+
|
10 |
+
from utils.multiple_stream import stream_data_in_column
|
11 |
+
|
12 |
+
if st.button("Stream data"):
|
13 |
+
# Define layout
|
14 |
+
columns = st.columns(2)
|
15 |
+
|
16 |
+
# Submit concurrent tasks
|
17 |
+
with ThreadPoolExecutor(max_workers=2) as executor:
|
18 |
+
ctx = get_script_run_ctx()
|
19 |
+
futures = [
|
20 |
+
executor.submit(stream_data_in_column, col, ctx) for col in columns
|
21 |
+
]
|
pages/summarization_example.py
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from dotenv import load_dotenv
|
2 |
+
from openai import OpenAI
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
st.write('## This is an example to show summarization')
|
8 |
+
|
9 |
+
examples = {
|
10 |
+
"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.
|
11 |
+
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.
|
12 |
+
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.
|
13 |
+
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.
|
14 |
+
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.""",
|
15 |
+
|
16 |
+
"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.
|
17 |
+
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.
|
18 |
+
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.
|
19 |
+
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.
|
20 |
+
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.
|
21 |
+
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.""",
|
22 |
+
}
|
23 |
+
|
24 |
+
def generate_answer(lm, sources, model_name="gpt-4o"): # noqa: ANN201, ANN001
|
25 |
+
meta_prompt = """
|
26 |
+
{sources}
|
27 |
+
|
28 |
+
summarization: """ # noqa: E501
|
29 |
+
content = meta_prompt.format(
|
30 |
+
sources=sources,
|
31 |
+
)
|
32 |
+
|
33 |
+
answer = lm.chat.completions.create(
|
34 |
+
temperature=0.8,
|
35 |
+
max_tokens=800,
|
36 |
+
messages=[
|
37 |
+
{
|
38 |
+
"role": "user",
|
39 |
+
"content": content,
|
40 |
+
},
|
41 |
+
],
|
42 |
+
model=model_name,
|
43 |
+
)
|
44 |
+
|
45 |
+
return answer
|
46 |
+
|
47 |
+
example_selection = st.selectbox("Choose an example", options=list(examples.keys()), index=0)
|
48 |
+
model_selection = st.selectbox("Choose a model", options=[
|
49 |
+
"gpt-3.5-turbo",
|
50 |
+
"gpt-4o",
|
51 |
+
"gpt-4"
|
52 |
+
], index=0)
|
53 |
+
|
54 |
+
# Input fields
|
55 |
+
input_text1 = st.text_area("question", height=None, \
|
56 |
+
placeholder="Enter first text here...", value=examples[example_selection])
|
57 |
+
|
58 |
+
|
59 |
+
|
60 |
+
# Button to trigger processing
|
61 |
+
lm = OpenAI()
|
62 |
+
|
63 |
+
if st.button('Submit'):
|
64 |
+
if input_text1:
|
65 |
+
response = generate_answer(lm, input_text1, model_selection)
|
66 |
+
st.write('## Orginal Article:')
|
67 |
+
st.markdown(examples[example_selection])
|
68 |
+
|
69 |
+
st.write('## Summarization:')
|
70 |
+
st.markdown(response.choices[0].message.content)
|
71 |
+
|
72 |
+
else:
|
73 |
+
# Show an error message if the required input is missing
|
74 |
+
st.error("Please fill both inputs to generate outputs.")
|
75 |
+
|
pyproject.toml
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[tool.poetry]
|
2 |
+
name = "chris_group_project"
|
3 |
+
version = "0.1.0"
|
4 |
+
description = "A collection and display of projects in Chris groups"
|
5 |
+
authors = ["Yanbo Fang <yanbofang0822@gmail.com>"]
|
6 |
+
|
7 |
+
[tool.poetry.dependencies]
|
8 |
+
python = "^3.11.9"
|
9 |
+
streamlit = "^1.2.0"
|
10 |
+
openai = "^1.35.3"
|
11 |
+
python-dotenv = "^0.19.1"
|
12 |
+
|
13 |
+
[tool.poetry.dev-dependencies]
|
14 |
+
pytest = "^6.2.3"
|
15 |
+
|
16 |
+
[tool.pytest.ini_options]
|
17 |
+
testpaths = [
|
18 |
+
"tests"
|
19 |
+
]
|
20 |
+
|
21 |
+
[build-system]
|
22 |
+
requires = ["poetry-core>=1.0.0"]
|
23 |
+
build-backend = "poetry.core.masonry.api"
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
openai==1.35.3
|
2 |
+
python-dotenv==0.19.1
|
utils/__init__.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# This is the __init__.py file for the utils package
|
2 |
+
# You can add any initialization code or import statements here
|
3 |
+
|
4 |
+
__all__ = ['multiple_stream']
|
utils/__pycache__/__init__.cpython-311.pyc
ADDED
Binary file (201 Bytes). View file
|
|
utils/__pycache__/multiple_stream.cpython-311.pyc
ADDED
Binary file (2.04 kB). View file
|
|
utils/multiple_stream.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
import random
|
3 |
+
from threading import currentThread
|
4 |
+
from time import sleep
|
5 |
+
|
6 |
+
import streamlit as st
|
7 |
+
from streamlit.runtime.scriptrunner.script_run_context import \
|
8 |
+
add_script_run_ctx
|
9 |
+
|
10 |
+
_TEST = """
|
11 |
+
Test of Time. A Benchmark for Evaluating LLMs on Temporal Reasoning. Large language models (LLMs) have \
|
12 |
+
showcased remarkable reasoning capabilities, yet they remain susceptible to errors, particularly in temporal \
|
13 |
+
reasoning tasks involving complex temporal logic.
|
14 |
+
"""
|
15 |
+
|
16 |
+
def generate_data_test():
|
17 |
+
"""A generator to pass to st.write_stream"""
|
18 |
+
temp = copy.deepcopy(_TEST)
|
19 |
+
l1 = temp.split()
|
20 |
+
random.shuffle(l1)
|
21 |
+
temp = ' '.join(l1)
|
22 |
+
|
23 |
+
for word in temp.split(" "):
|
24 |
+
print(word)
|
25 |
+
yield word + " "
|
26 |
+
sleep(0.1)
|
27 |
+
|
28 |
+
|
29 |
+
def stream_data_in_column(column, ctx):
|
30 |
+
"""Populate columns simultaneously"""
|
31 |
+
|
32 |
+
add_script_run_ctx(currentThread(), ctx)
|
33 |
+
print("11111111")
|
34 |
+
with column:
|
35 |
+
st.write_stream(generate_data_test)
|