Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- .DS_Store +0 -0
- .github/workflows/update_space.yml +28 -0
- .gitignore +171 -0
- .gradio/certificate.pem +31 -0
- README.md +4 -9
- assistant.py +131 -0
- assistant_data.json +1 -0
- create.py +59 -0
- file_data.json +1 -0
- makefile +0 -0
- requirements.txt +5 -0
- vector_data.json +1 -0
.DS_Store
ADDED
|
Binary file (6.15 kB). View file
|
|
|
.github/workflows/update_space.yml
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Run Python script
|
| 2 |
+
|
| 3 |
+
on:
|
| 4 |
+
push:
|
| 5 |
+
branches:
|
| 6 |
+
- main
|
| 7 |
+
|
| 8 |
+
jobs:
|
| 9 |
+
build:
|
| 10 |
+
runs-on: ubuntu-latest
|
| 11 |
+
|
| 12 |
+
steps:
|
| 13 |
+
- name: Checkout
|
| 14 |
+
uses: actions/checkout@v2
|
| 15 |
+
|
| 16 |
+
- name: Set up Python
|
| 17 |
+
uses: actions/setup-python@v2
|
| 18 |
+
with:
|
| 19 |
+
python-version: '3.9'
|
| 20 |
+
|
| 21 |
+
- name: Install Gradio
|
| 22 |
+
run: python -m pip install gradio
|
| 23 |
+
|
| 24 |
+
- name: Log in to Hugging Face
|
| 25 |
+
run: python -c 'import huggingface_hub; huggingface_hub.login(token="${{ secrets.hf_token }}")'
|
| 26 |
+
|
| 27 |
+
- name: Deploy to Spaces
|
| 28 |
+
run: gradio deploy
|
.gitignore
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
| 4 |
+
*$py.class
|
| 5 |
+
|
| 6 |
+
# C extensions
|
| 7 |
+
*.so
|
| 8 |
+
|
| 9 |
+
# Distribution / packaging
|
| 10 |
+
.Python
|
| 11 |
+
build/
|
| 12 |
+
develop-eggs/
|
| 13 |
+
dist/
|
| 14 |
+
downloads/
|
| 15 |
+
eggs/
|
| 16 |
+
.eggs/
|
| 17 |
+
lib/
|
| 18 |
+
lib64/
|
| 19 |
+
parts/
|
| 20 |
+
sdist/
|
| 21 |
+
var/
|
| 22 |
+
wheels/
|
| 23 |
+
share/python-wheels/
|
| 24 |
+
*.egg-info/
|
| 25 |
+
.installed.cfg
|
| 26 |
+
*.egg
|
| 27 |
+
MANIFEST
|
| 28 |
+
|
| 29 |
+
# PyInstaller
|
| 30 |
+
# Usually these files are written by a python script from a template
|
| 31 |
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
| 32 |
+
*.manifest
|
| 33 |
+
*.spec
|
| 34 |
+
|
| 35 |
+
# Installer logs
|
| 36 |
+
pip-log.txt
|
| 37 |
+
pip-delete-this-directory.txt
|
| 38 |
+
|
| 39 |
+
# Unit test / coverage reports
|
| 40 |
+
htmlcov/
|
| 41 |
+
.tox/
|
| 42 |
+
.nox/
|
| 43 |
+
.coverage
|
| 44 |
+
.coverage.*
|
| 45 |
+
.cache
|
| 46 |
+
nosetests.xml
|
| 47 |
+
coverage.xml
|
| 48 |
+
*.cover
|
| 49 |
+
*.py,cover
|
| 50 |
+
.hypothesis/
|
| 51 |
+
.pytest_cache/
|
| 52 |
+
cover/
|
| 53 |
+
|
| 54 |
+
# Translations
|
| 55 |
+
*.mo
|
| 56 |
+
*.pot
|
| 57 |
+
|
| 58 |
+
# Django stuff:
|
| 59 |
+
*.log
|
| 60 |
+
local_settings.py
|
| 61 |
+
db.sqlite3
|
| 62 |
+
db.sqlite3-journal
|
| 63 |
+
|
| 64 |
+
# Flask stuff:
|
| 65 |
+
instance/
|
| 66 |
+
.webassets-cache
|
| 67 |
+
|
| 68 |
+
# Scrapy stuff:
|
| 69 |
+
.scrapy
|
| 70 |
+
|
| 71 |
+
# Sphinx documentation
|
| 72 |
+
docs/_build/
|
| 73 |
+
|
| 74 |
+
# PyBuilder
|
| 75 |
+
.pybuilder/
|
| 76 |
+
target/
|
| 77 |
+
|
| 78 |
+
# Jupyter Notebook
|
| 79 |
+
.ipynb_checkpoints
|
| 80 |
+
|
| 81 |
+
# IPython
|
| 82 |
+
profile_default/
|
| 83 |
+
ipython_config.py
|
| 84 |
+
|
| 85 |
+
# pyenv
|
| 86 |
+
# For a library or package, you might want to ignore these files since the code is
|
| 87 |
+
# intended to run in multiple environments; otherwise, check them in:
|
| 88 |
+
# .python-version
|
| 89 |
+
|
| 90 |
+
# pipenv
|
| 91 |
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
| 92 |
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
| 93 |
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
| 94 |
+
# install all needed dependencies.
|
| 95 |
+
#Pipfile.lock
|
| 96 |
+
|
| 97 |
+
# UV
|
| 98 |
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
| 99 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 100 |
+
# commonly ignored for libraries.
|
| 101 |
+
#uv.lock
|
| 102 |
+
|
| 103 |
+
# poetry
|
| 104 |
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
| 105 |
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
| 106 |
+
# commonly ignored for libraries.
|
| 107 |
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
| 108 |
+
#poetry.lock
|
| 109 |
+
|
| 110 |
+
# pdm
|
| 111 |
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
| 112 |
+
#pdm.lock
|
| 113 |
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
| 114 |
+
# in version control.
|
| 115 |
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
| 116 |
+
.pdm.toml
|
| 117 |
+
.pdm-python
|
| 118 |
+
.pdm-build/
|
| 119 |
+
|
| 120 |
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
| 121 |
+
__pypackages__/
|
| 122 |
+
|
| 123 |
+
# Celery stuff
|
| 124 |
+
celerybeat-schedule
|
| 125 |
+
celerybeat.pid
|
| 126 |
+
|
| 127 |
+
# SageMath parsed files
|
| 128 |
+
*.sage.py
|
| 129 |
+
|
| 130 |
+
# Environments
|
| 131 |
+
.env
|
| 132 |
+
.venv
|
| 133 |
+
env/
|
| 134 |
+
venv/
|
| 135 |
+
ENV/
|
| 136 |
+
env.bak/
|
| 137 |
+
venv.bak/
|
| 138 |
+
|
| 139 |
+
# Spyder project settings
|
| 140 |
+
.spyderproject
|
| 141 |
+
.spyproject
|
| 142 |
+
|
| 143 |
+
# Rope project settings
|
| 144 |
+
.ropeproject
|
| 145 |
+
|
| 146 |
+
# mkdocs documentation
|
| 147 |
+
/site
|
| 148 |
+
|
| 149 |
+
# mypy
|
| 150 |
+
.mypy_cache/
|
| 151 |
+
.dmypy.json
|
| 152 |
+
dmypy.json
|
| 153 |
+
|
| 154 |
+
# Pyre type checker
|
| 155 |
+
.pyre/
|
| 156 |
+
|
| 157 |
+
# pytype static type analyzer
|
| 158 |
+
.pytype/
|
| 159 |
+
|
| 160 |
+
# Cython debug symbols
|
| 161 |
+
cython_debug/
|
| 162 |
+
|
| 163 |
+
# PyCharm
|
| 164 |
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
| 165 |
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
| 166 |
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
| 167 |
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
| 168 |
+
#.idea/
|
| 169 |
+
|
| 170 |
+
# PyPI configuration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zsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
README.md
CHANGED
|
@@ -1,12 +1,7 @@
|
|
| 1 |
---
|
| 2 |
-
title: Fair
|
| 3 |
-
|
| 4 |
-
colorFrom: gray
|
| 5 |
-
colorTo: yellow
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 5.
|
| 8 |
-
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Fair-Admissions-Advisor
|
| 3 |
+
app_file: assistant.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 5.16.2
|
| 6 |
+
colorTo: red
|
|
|
|
| 7 |
---
|
|
|
|
|
|
assistant.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import openai
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
import dotenv
|
| 6 |
+
import time
|
| 7 |
+
import re
|
| 8 |
+
|
| 9 |
+
dotenv.load_dotenv()
|
| 10 |
+
threads = []
|
| 11 |
+
# OpenAI API Key
|
| 12 |
+
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY"))
|
| 13 |
+
ASSISTANT_ID = os.environ.get("ASSISTANT_ID")
|
| 14 |
+
|
| 15 |
+
# Get the assistant ID and field ids(reuses if already created)
|
| 16 |
+
history = [
|
| 17 |
+
gr.ChatMessage(role="assistant", content="Hello! I can help you explore how Free School Meal (FSM) rates at your school compare to deprivation levels in the local community—and what that might mean for fair access to education. Just tell me your school’s name to get started."),
|
| 18 |
+
]
|
| 19 |
+
def submit_message(thread, user_message):
|
| 20 |
+
print(user_message)
|
| 21 |
+
|
| 22 |
+
userFileIds = []
|
| 23 |
+
|
| 24 |
+
client.beta.threads.messages.create(
|
| 25 |
+
thread_id=thread.id, role="user", content=user_message,
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
return client.beta.threads.runs.create(
|
| 29 |
+
thread_id=thread.id,
|
| 30 |
+
assistant_id=ASSISTANT_ID,
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
def create_thread_and_run(user_input):
|
| 34 |
+
thread = client.beta.threads.create()
|
| 35 |
+
run = submit_message( thread, user_input)
|
| 36 |
+
print(run.usage)
|
| 37 |
+
return {'thread':thread, 'run':run}
|
| 38 |
+
|
| 39 |
+
# def checkForExampleChange(history):
|
| 40 |
+
# last_message = history[-1].get("content", "").lower()
|
| 41 |
+
|
| 42 |
+
# if 'admissions' in last_message or 'admission' in last_message:
|
| 43 |
+
# print("Example changed")
|
| 44 |
+
# examples = [
|
| 45 |
+
# "Tell me about Catchment area admissions",
|
| 46 |
+
# "Tell me about Sibling admissions",
|
| 47 |
+
# "Tell me about Faith admissions",
|
| 48 |
+
# "Tell me about Open admissions",
|
| 49 |
+
# "Tell me about Random admissions",
|
| 50 |
+
# "Tell me about Priority admissions",
|
| 51 |
+
# "Tell me about Banding admissions",
|
| 52 |
+
# "Show me research about school admissions",
|
| 53 |
+
# ]
|
| 54 |
+
# cb.examples= examples
|
| 55 |
+
# else:
|
| 56 |
+
# print("Example not changed")
|
| 57 |
+
def get_response(thread):
|
| 58 |
+
history = []
|
| 59 |
+
messages = client.beta.threads.messages.list(thread_id=thread.id, order="desc")
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
for m in messages:
|
| 63 |
+
message_text = m.content[0].text.value
|
| 64 |
+
regex_pattern = r"【.*?】"
|
| 65 |
+
|
| 66 |
+
cleaned_string = re.sub(regex_pattern, '', message_text)
|
| 67 |
+
print(f"{m.role}: {m.content[0].text.value}")
|
| 68 |
+
obj = {"role" :m.role, "content": cleaned_string}
|
| 69 |
+
history.append(obj)
|
| 70 |
+
# checkForExampleChange(history)
|
| 71 |
+
return history
|
| 72 |
+
# Waiting in a loop
|
| 73 |
+
def wait_on_run(run, thread):
|
| 74 |
+
while run.status == "queued" or run.status == "in_progress":
|
| 75 |
+
run = client.beta.threads.runs.retrieve(
|
| 76 |
+
thread_id=thread.id,
|
| 77 |
+
run_id=run.id,
|
| 78 |
+
)
|
| 79 |
+
time.sleep(0.5)
|
| 80 |
+
print(run.status)
|
| 81 |
+
return run
|
| 82 |
+
|
| 83 |
+
def process(user_input, history):
|
| 84 |
+
toProcess = create_thread_and_run(
|
| 85 |
+
user_input
|
| 86 |
+
)
|
| 87 |
+
run = wait_on_run(toProcess.get("run"), toProcess.get("thread"))
|
| 88 |
+
thread = toProcess.get("thread")
|
| 89 |
+
print(run)
|
| 90 |
+
if run.status != "completed":
|
| 91 |
+
raise Exception(f"Run failed with status: {run.status}")
|
| 92 |
+
else:
|
| 93 |
+
return get_response(thread)[0].get("content")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
css = """
|
| 97 |
+
.placeholder {
|
| 98 |
+
display: flex;
|
| 99 |
+
justify-content: center;
|
| 100 |
+
align-items: center;
|
| 101 |
+
padding: 20px;
|
| 102 |
+
text-align: center; /* Center text horizontally */
|
| 103 |
+
height:100%
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
.placeholder > p{
|
| 107 |
+
margin: 0;
|
| 108 |
+
}
|
| 109 |
+
"""
|
| 110 |
+
with gr.Blocks(css=css) as demo:
|
| 111 |
+
title = gr.Markdown(
|
| 112 |
+
"""
|
| 113 |
+
<h2>Fair Admissions Advisor</h2>
|
| 114 |
+
"""
|
| 115 |
+
)
|
| 116 |
+
examples = [
|
| 117 |
+
"Compare Free School Meal rates for a school",
|
| 118 |
+
"Can you explain a specific type of school admission policy?",
|
| 119 |
+
"Show me research about school admissions",
|
| 120 |
+
]
|
| 121 |
+
ci = gr.ChatInterface(
|
| 122 |
+
chatbot=gr.Chatbot([], type='messages', placeholder="Hello! I can help you explore how Free School Meal (FSM) rates at your school compare to deprivation levels in the local community—and what that might mean for fair access to education. Just tell me your school’s name to get started."),
|
| 123 |
+
|
| 124 |
+
fn=process,
|
| 125 |
+
examples=examples,
|
| 126 |
+
type='messages',
|
| 127 |
+
),
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
demo.launch()
|
assistant_data.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"assistant_id": "asst_URwetnNCsUQrP5X0VtpFglJe"}
|
create.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
import dotenv
|
| 4 |
+
from openai import OpenAI
|
| 5 |
+
|
| 6 |
+
import openai
|
| 7 |
+
from store import save_assistant_id, load_assistant_id # Import from your store module
|
| 8 |
+
dotenv.load_dotenv()
|
| 9 |
+
|
| 10 |
+
# OpenAI API Key
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Example usage (replace with your actual file paths)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Store user sessions (threads)
|
| 19 |
+
import openai
|
| 20 |
+
import os
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def create_assistant(client): # Add client and optional parameters
|
| 24 |
+
"""Retrieves existing assistant ID or creates a new one if not found."""
|
| 25 |
+
|
| 26 |
+
ASSISTANT_ID = load_assistant_id() # Try to load existing ID
|
| 27 |
+
|
| 28 |
+
if ASSISTANT_ID is None: # Create if not found
|
| 29 |
+
try:
|
| 30 |
+
# Create new assistant if none exists
|
| 31 |
+
assistant = client.beta.assistants.create(
|
| 32 |
+
name="Admissions Assistant",
|
| 33 |
+
instructions=" Take in the users school information and what kind of admissions policy they use. You help users by answering queries and giving feedback on the schools admissions policies. And offer to compare Free school meals data from neighbouring schools in the spreadsheet ",
|
| 34 |
+
tools=[{"type": "file_search"}], # Uses OpenAI’s built-in vector store
|
| 35 |
+
model="gpt-4o-mini"
|
| 36 |
+
)
|
| 37 |
+
ASSISTANT_ID = assistant.id
|
| 38 |
+
save_assistant_id(ASSISTANT_ID) # Save the new ID
|
| 39 |
+
print(f"New assistant created with ID: {ASSISTANT_ID}")
|
| 40 |
+
except Exception as e: # Handle potential errors during assistant creation
|
| 41 |
+
print(f"Error creating assistant: {e}")
|
| 42 |
+
return None # Return None to indicate failure
|
| 43 |
+
|
| 44 |
+
else:
|
| 45 |
+
print(f"Using existing assistant with ID: {ASSISTANT_ID}")
|
| 46 |
+
|
| 47 |
+
return ASSISTANT_ID # Return the assistant ID (whether existing or newly created)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
client = OpenAI()
|
| 54 |
+
create_assistant(client)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
|
file_data.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"file_ids": ["file-W4AhQ347Sevk25GGLdsKzV", "file-8WnTuEngPpY1Bw2J1fkkZ5", "file-VQLcs39bvCuJVCTswPRumx", "file-XrdtvoMwpJcwd79yFXKR4K", "file-78jD4FwCusvhkms68H5Gwd"]}
|
makefile
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
openai
|
| 3 |
+
python-dotenv
|
| 4 |
+
requests
|
| 5 |
+
pypdf
|
vector_data.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"vector_id": "vs_67b89fe6267c819190215a2086624c1a"}
|