Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,8 @@ api_key = os.getenv("api_key")
|
|
| 19 |
# Load the OpenAI API key
|
| 20 |
openai.api_key = api_key
|
| 21 |
|
|
|
|
|
|
|
| 22 |
def ask_chatbot(query, chat_history, project_data):
|
| 23 |
# Convert project_data to a string format (optional: simplify or summarize if needed)
|
| 24 |
project_data_str = json.dumps(project_data, indent=2)
|
|
@@ -54,18 +56,20 @@ def ask_chatbot(query, chat_history, project_data):
|
|
| 54 |
return answer
|
| 55 |
|
| 56 |
def generate_response(message, history):
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
with open("/content/project_data.json", 'r') as f:
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
def upload_file(data_file):
|
| 64 |
-
|
| 65 |
data = json.load(f)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
json.dump(data, f)
|
|
|
|
|
|
|
| 69 |
|
| 70 |
with gr.Blocks() as demo:
|
| 71 |
gr.ChatInterface(
|
|
|
|
| 19 |
# Load the OpenAI API key
|
| 20 |
openai.api_key = api_key
|
| 21 |
|
| 22 |
+
project_data = {}
|
| 23 |
+
|
| 24 |
def ask_chatbot(query, chat_history, project_data):
|
| 25 |
# Convert project_data to a string format (optional: simplify or summarize if needed)
|
| 26 |
project_data_str = json.dumps(project_data, indent=2)
|
|
|
|
| 56 |
return answer
|
| 57 |
|
| 58 |
def generate_response(message, history):
|
| 59 |
+
# project_data = {}
|
| 60 |
+
# if os.path.exists("/content/project_data.json"):
|
| 61 |
+
# with open("/content/project_data.json", 'r') as f:
|
| 62 |
+
# project_data = json.load(f)
|
| 63 |
+
return ask_chatbot(message, history, project_data)
|
| 64 |
|
| 65 |
def upload_file(data_file):
|
| 66 |
+
with open(data_file.name, "r") as f:
|
| 67 |
data = json.load(f)
|
| 68 |
+
gr.Info("Project file Uploaded. You can now query the document")
|
| 69 |
+
# with open("/content/project_data.json", "w") as f:
|
| 70 |
+
# json.dump(data, f)
|
| 71 |
+
global project_data
|
| 72 |
+
project_data = data
|
| 73 |
|
| 74 |
with gr.Blocks() as demo:
|
| 75 |
gr.ChatInterface(
|