Spaces:
Build error
Build error
first commit
Browse files- app.py +61 -0
- requirements.txt +169 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import os
|
| 3 |
+
import openai
|
| 4 |
+
|
| 5 |
+
def process_text(file_path,api_key):
|
| 6 |
+
result = "Thank you. Total word count for your input file, original file and summary:"
|
| 7 |
+
word_count = len(file_path.split())
|
| 8 |
+
openai.api_key = api_key
|
| 9 |
+
|
| 10 |
+
response = openai.ChatCompletion.create(
|
| 11 |
+
model="gpt-3.5-turbo",
|
| 12 |
+
messages=[
|
| 13 |
+
{
|
| 14 |
+
"role": "system",
|
| 15 |
+
"content": "You are a helpful assistant."
|
| 16 |
+
},
|
| 17 |
+
{
|
| 18 |
+
"role": "user",
|
| 19 |
+
"content": "Summarize the following text in 100 words" + file_path
|
| 20 |
+
}
|
| 21 |
+
]
|
| 22 |
+
)
|
| 23 |
+
summary=(response['choices'][0]['message']['content'])
|
| 24 |
+
|
| 25 |
+
return result, file_path, word_count, summary
|
| 26 |
+
# Your function logic here
|
| 27 |
+
# Process the text file and return the output
|
| 28 |
+
|
| 29 |
+
# Streamlit app code
|
| 30 |
+
def main():
|
| 31 |
+
"""
|
| 32 |
+
The main function is the entry point of the program. It displays a web interface using the Streamlit library, allowing users to upload a text file, process its contents, and display the output.
|
| 33 |
+
|
| 34 |
+
:return: None
|
| 35 |
+
"""
|
| 36 |
+
st.title("Demo to use OpenAI to Summarize Text, Jack Lau")
|
| 37 |
+
|
| 38 |
+
# File input
|
| 39 |
+
file = st.file_uploader("Upload a text file", type=["txt"])
|
| 40 |
+
|
| 41 |
+
# Set up your OpenAI API credentials
|
| 42 |
+
api_key = st.text_input('Enter a text string', 'Your API key here')
|
| 43 |
+
st.write('Enter Your OpenAI API Key', api_key)
|
| 44 |
+
st.button("Submit")
|
| 45 |
+
|
| 46 |
+
if file is not None:
|
| 47 |
+
# Read the file
|
| 48 |
+
text = file.read().decode()
|
| 49 |
+
|
| 50 |
+
# Process the text file
|
| 51 |
+
output = process_text(text, api_key)
|
| 52 |
+
|
| 53 |
+
# Display the output
|
| 54 |
+
st.subheader("Original File and Number of Words")
|
| 55 |
+
st.write(output[1])
|
| 56 |
+
st.write(output[2])
|
| 57 |
+
st.subheader("Summary by A.I.")
|
| 58 |
+
st.write(output[3])
|
| 59 |
+
|
| 60 |
+
if __name__ == "__main__":
|
| 61 |
+
main()
|
requirements.txt
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiohttp==3.8.4
|
| 2 |
+
aiosignal==1.3.1
|
| 3 |
+
altair==5.1.0
|
| 4 |
+
anyio==3.7.0
|
| 5 |
+
argilla==1.8.0
|
| 6 |
+
async-timeout==4.0.2
|
| 7 |
+
attrs==23.1.0
|
| 8 |
+
backoff==2.2.1
|
| 9 |
+
backports.zoneinfo==0.2.1
|
| 10 |
+
beautifulsoup4==4.12.2
|
| 11 |
+
blinker==1.6.2
|
| 12 |
+
cachetools==5.3.1
|
| 13 |
+
certifi==2023.5.7
|
| 14 |
+
cffi==1.15.1
|
| 15 |
+
chardet==5.1.0
|
| 16 |
+
charset-normalizer==3.1.0
|
| 17 |
+
chromadb==0.3.23
|
| 18 |
+
click==8.1.7
|
| 19 |
+
clickhouse-connect==0.5.25
|
| 20 |
+
cmake==3.26.3
|
| 21 |
+
colorclass==2.2.2
|
| 22 |
+
commonmark==0.9.1
|
| 23 |
+
compressed-rtf==1.0.6
|
| 24 |
+
cryptography==41.0.1
|
| 25 |
+
dataclasses-json==0.5.7
|
| 26 |
+
Deprecated==1.2.14
|
| 27 |
+
-e git+https://github.com/vivek3141/ghostbuster.git@7e700080e27d05668cd3d35891417f2dee2ef35e#egg=detect_ai
|
| 28 |
+
dill==0.3.7
|
| 29 |
+
duckdb==0.8.0
|
| 30 |
+
easygui==0.98.3
|
| 31 |
+
ebcdic==1.1.1
|
| 32 |
+
et-xmlfile==1.1.0
|
| 33 |
+
exceptiongroup==1.1.1
|
| 34 |
+
extract-msg==0.41.1
|
| 35 |
+
fastapi==0.95.2
|
| 36 |
+
filelock==3.12.0
|
| 37 |
+
Flask==2.3.3
|
| 38 |
+
frozenlist==1.3.3
|
| 39 |
+
fsspec==2023.5.0
|
| 40 |
+
gitdb==4.0.10
|
| 41 |
+
GitPython==3.1.32
|
| 42 |
+
gpt4all==0.2.3
|
| 43 |
+
greenlet==2.0.2
|
| 44 |
+
h11==0.14.0
|
| 45 |
+
hnswlib==0.7.0
|
| 46 |
+
httpcore==0.16.3
|
| 47 |
+
httptools==0.5.0
|
| 48 |
+
httpx==0.23.3
|
| 49 |
+
huggingface-hub==0.15.1
|
| 50 |
+
idna==3.4
|
| 51 |
+
IMAPClient==2.3.1
|
| 52 |
+
importlib-metadata==6.6.0
|
| 53 |
+
importlib-resources==6.0.1
|
| 54 |
+
itsdangerous==2.1.2
|
| 55 |
+
Jinja2==3.1.2
|
| 56 |
+
joblib==1.2.0
|
| 57 |
+
jsonschema==4.19.0
|
| 58 |
+
jsonschema-specifications==2023.7.1
|
| 59 |
+
langchain==0.0.177
|
| 60 |
+
lark-parser==0.12.0
|
| 61 |
+
lit==16.0.5
|
| 62 |
+
llama-cpp-python==0.1.50
|
| 63 |
+
lxml==4.9.2
|
| 64 |
+
lz4==4.3.2
|
| 65 |
+
Markdown==3.4.3
|
| 66 |
+
MarkupSafe==2.1.3
|
| 67 |
+
marshmallow==3.19.0
|
| 68 |
+
marshmallow-enum==1.5.1
|
| 69 |
+
mpmath==1.3.0
|
| 70 |
+
msg-parser==1.2.0
|
| 71 |
+
msoffcrypto-tool==5.0.1
|
| 72 |
+
multidict==6.0.4
|
| 73 |
+
mypy-extensions==1.0.0
|
| 74 |
+
networkx==3.1
|
| 75 |
+
nltk==3.8.1
|
| 76 |
+
numexpr==2.8.4
|
| 77 |
+
numpy==1.24.3
|
| 78 |
+
nvidia-cublas-cu11==11.10.3.66
|
| 79 |
+
nvidia-cuda-cupti-cu11==11.7.101
|
| 80 |
+
nvidia-cuda-nvrtc-cu11==11.7.99
|
| 81 |
+
nvidia-cuda-runtime-cu11==11.7.99
|
| 82 |
+
nvidia-cudnn-cu11==8.5.0.96
|
| 83 |
+
nvidia-cufft-cu11==10.9.0.58
|
| 84 |
+
nvidia-curand-cu11==10.2.10.91
|
| 85 |
+
nvidia-cusolver-cu11==11.4.0.1
|
| 86 |
+
nvidia-cusparse-cu11==11.7.4.91
|
| 87 |
+
nvidia-nccl-cu11==2.14.3
|
| 88 |
+
nvidia-nvtx-cu11==11.7.91
|
| 89 |
+
oletools==0.60.1
|
| 90 |
+
openai==0.27.9
|
| 91 |
+
openapi-schema-pydantic==1.2.4
|
| 92 |
+
openpyxl==3.1.2
|
| 93 |
+
packaging==23.1
|
| 94 |
+
pandas==2.0.2
|
| 95 |
+
pandoc==2.3
|
| 96 |
+
pcodedmp==1.2.6
|
| 97 |
+
pdfminer.six==20221105
|
| 98 |
+
Pillow==9.5.0
|
| 99 |
+
pkgutil_resolve_name==1.3.10
|
| 100 |
+
plumbum==1.8.2
|
| 101 |
+
posthog==3.0.1
|
| 102 |
+
protobuf==4.24.2
|
| 103 |
+
pyarrow==13.0.0
|
| 104 |
+
pycparser==2.21
|
| 105 |
+
pydantic==1.10.8
|
| 106 |
+
pydeck==0.8.0
|
| 107 |
+
Pygments==2.15.1
|
| 108 |
+
Pympler==1.0.1
|
| 109 |
+
pypandoc==1.11
|
| 110 |
+
python-dateutil==2.8.2
|
| 111 |
+
python-docx==0.8.11
|
| 112 |
+
python-dotenv==1.0.0
|
| 113 |
+
python-magic==0.4.27
|
| 114 |
+
python-pptx==0.6.21
|
| 115 |
+
pytz==2023.3
|
| 116 |
+
pytz-deprecation-shim==0.1.0.post0
|
| 117 |
+
PyYAML==6.0
|
| 118 |
+
red-black-tree-mod==1.20
|
| 119 |
+
referencing==0.30.2
|
| 120 |
+
regex==2023.5.5
|
| 121 |
+
requests==2.31.0
|
| 122 |
+
rfc3986==1.5.0
|
| 123 |
+
rich==13.0.1
|
| 124 |
+
rpds-py==0.10.0
|
| 125 |
+
RTFDE==0.0.2
|
| 126 |
+
scikit-learn==1.2.2
|
| 127 |
+
scipy==1.10.1
|
| 128 |
+
sentence-transformers==2.2.2
|
| 129 |
+
sentencepiece==0.1.99
|
| 130 |
+
six==1.16.0
|
| 131 |
+
smmap==5.0.0
|
| 132 |
+
sniffio==1.3.0
|
| 133 |
+
soupsieve==2.4.1
|
| 134 |
+
SQLAlchemy==2.0.15
|
| 135 |
+
starlette==0.27.0
|
| 136 |
+
streamlit==1.26.0
|
| 137 |
+
sympy==1.12
|
| 138 |
+
tabulate==0.9.0
|
| 139 |
+
tenacity==8.2.2
|
| 140 |
+
threadpoolctl==3.1.0
|
| 141 |
+
tiktoken==0.4.0
|
| 142 |
+
tokenizers==0.13.3
|
| 143 |
+
toml==0.10.2
|
| 144 |
+
toolz==0.12.0
|
| 145 |
+
torch==2.0.1
|
| 146 |
+
torchvision==0.15.2
|
| 147 |
+
tornado==6.3.3
|
| 148 |
+
tqdm==4.65.0
|
| 149 |
+
transformers==4.29.2
|
| 150 |
+
triton==2.0.0
|
| 151 |
+
typer==0.9.0
|
| 152 |
+
typing-inspect==0.9.0
|
| 153 |
+
typing_extensions==4.6.3
|
| 154 |
+
tzdata==2023.3
|
| 155 |
+
tzlocal==4.2
|
| 156 |
+
unstructured==0.6.6
|
| 157 |
+
urllib3==2.0.2
|
| 158 |
+
uvicorn==0.22.0
|
| 159 |
+
uvloop==0.17.0
|
| 160 |
+
validators==0.21.2
|
| 161 |
+
watchdog==3.0.0
|
| 162 |
+
watchfiles==0.19.0
|
| 163 |
+
websockets==11.0.3
|
| 164 |
+
Werkzeug==2.3.7
|
| 165 |
+
wrapt==1.14.1
|
| 166 |
+
XlsxWriter==3.1.2
|
| 167 |
+
yarl==1.9.2
|
| 168 |
+
zipp==3.16.2
|
| 169 |
+
zstandard==0.21.0
|