Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,25 +6,51 @@ import uuid
|
|
| 6 |
import time
|
| 7 |
import os
|
| 8 |
import openai
|
|
|
|
| 9 |
|
| 10 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 11 |
|
| 12 |
# Set your OpenAI Assistant ID here
|
| 13 |
assistant_id = os.getenv("assistant_id")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def main():
|
| 16 |
|
| 17 |
if 'client' not in st.session_state:
|
| 18 |
# Initialize the client
|
| 19 |
st.session_state.client = openai.OpenAI()
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Step 1: Create an Assistant
|
| 23 |
st.session_state.assistant = st.session_state.client.beta.assistants.create(
|
| 24 |
-
name="
|
| 25 |
-
instructions="You are a
|
| 26 |
model="gpt-4-1106-preview",
|
| 27 |
-
|
|
|
|
| 28 |
)
|
| 29 |
|
| 30 |
# Step 2: Create a Thread
|
|
|
|
| 6 |
import time
|
| 7 |
import os
|
| 8 |
import openai
|
| 9 |
+
import pandas as pd
|
| 10 |
|
| 11 |
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
|
| 12 |
|
| 13 |
# Set your OpenAI Assistant ID here
|
| 14 |
assistant_id = os.getenv("assistant_id")
|
| 15 |
|
| 16 |
+
|
| 17 |
+
# Step 1: Clone the Dataset Repository
|
| 18 |
+
repo = Repository(
|
| 19 |
+
local_dir="Test_csv", # Local directory to clone the repository
|
| 20 |
+
repo_type="dataset",
|
| 21 |
+
clone_from="Anne31415/Test_csv",
|
| 22 |
+
token=os.environ["HUB_TOKEN"] # Token for authentication
|
| 23 |
+
)
|
| 24 |
+
repo.git_pull() # Pull the latest changes (if any)
|
| 25 |
+
|
| 26 |
+
# Step 2: Load the PDF File
|
| 27 |
+
file_path = "Test_csv/Basic_Info_GrunddatenKH141123.csv"
|
| 28 |
+
|
| 29 |
+
file = client.files.create(
|
| 30 |
+
file=open(file_path, "rb"),
|
| 31 |
+
purpose='assistants'
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
def main():
|
| 37 |
|
| 38 |
if 'client' not in st.session_state:
|
| 39 |
# Initialize the client
|
| 40 |
st.session_state.client = openai.OpenAI()
|
| 41 |
|
| 42 |
+
st.session_state.file = st.session_state.client.files.create(
|
| 43 |
+
file,
|
| 44 |
+
purpose='assistants'
|
| 45 |
+
)
|
| 46 |
|
| 47 |
# Step 1: Create an Assistant
|
| 48 |
st.session_state.assistant = st.session_state.client.beta.assistants.create(
|
| 49 |
+
name="Medical Data Analyst",
|
| 50 |
+
instructions="You are a data analyst for medical data. Use your csv knowlagebase to answer the given questions. Make plots if it fits the question.",
|
| 51 |
model="gpt-4-1106-preview",
|
| 52 |
+
file_ids=[st.session_state.file.id],
|
| 53 |
+
tools=[{"type": "code_interpreter"}]
|
| 54 |
)
|
| 55 |
|
| 56 |
# Step 2: Create a Thread
|