Spaces:
Sleeping
Sleeping
Update app_gpu.py
Browse files- app_gpu.py +10 -14
app_gpu.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
import openai
|
| 5 |
from dotenv import load_dotenv
|
|
@@ -66,7 +66,7 @@ class cbfs:
|
|
| 66 |
return_generated_question=True,
|
| 67 |
)
|
| 68 |
|
| 69 |
-
|
| 70 |
def convchain(self, query):
|
| 71 |
if not query:
|
| 72 |
return [("User", ""), ("ChatBot", "")]
|
|
@@ -94,18 +94,17 @@ def initialize_cbfs(db_choice, model_choice):
|
|
| 94 |
else:
|
| 95 |
return None
|
| 96 |
|
| 97 |
-
def chat_history(query, db_choice, model_choice
|
| 98 |
-
# def chat_history(query, db_choice, model_choice):
|
| 99 |
"""Handles chat submissions. Reminds the user to select a document if none is selected."""
|
| 100 |
-
|
| 101 |
if cb is None: # If cb is not initialized, remind to select a document
|
| 102 |
return [("ChatBot", "Please select a document from the dropdown menu before submitting your query.")], ""
|
| 103 |
else:
|
| 104 |
return cb.convchain(query), "" # Clear input box by returning empty string
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
if cb is None: # Check if cbfs instance is None
|
| 110 |
return [], "" # No error message, simply clear the UI components
|
| 111 |
else:
|
|
@@ -159,13 +158,10 @@ with gr.Blocks() as demo:
|
|
| 159 |
)
|
| 160 |
|
| 161 |
# Define interactions for both submit button and Enter key
|
| 162 |
-
inp.submit(fn=chat_history, inputs=[inp, db_choice, model_choice, cbfs_instance], outputs=[output, inp])
|
| 163 |
-
button_submit.click(fn=chat_history, inputs=[inp, db_choice, model_choice, cbfs_instance], outputs=[output, inp])
|
| 164 |
-
button_clearhistory.click(fn=clear_history, inputs=cbfs_instance, outputs=[output, inp])
|
| 165 |
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
|
| 170 |
|
| 171 |
# Launch the Gradio app
|
|
|
|
| 1 |
|
| 2 |
+
import spaces
|
| 3 |
import os
|
| 4 |
import openai
|
| 5 |
from dotenv import load_dotenv
|
|
|
|
| 66 |
return_generated_question=True,
|
| 67 |
)
|
| 68 |
|
| 69 |
+
@spaces.GPU
|
| 70 |
def convchain(self, query):
|
| 71 |
if not query:
|
| 72 |
return [("User", ""), ("ChatBot", "")]
|
|
|
|
| 94 |
else:
|
| 95 |
return None
|
| 96 |
|
| 97 |
+
def chat_history(query, db_choice, model_choice):
|
|
|
|
| 98 |
"""Handles chat submissions. Reminds the user to select a document if none is selected."""
|
| 99 |
+
cb = initialize_cbfs(db_choice, model_choice) # Reinitialize cbfs
|
| 100 |
if cb is None: # If cb is not initialized, remind to select a document
|
| 101 |
return [("ChatBot", "Please select a document from the dropdown menu before submitting your query.")], ""
|
| 102 |
else:
|
| 103 |
return cb.convchain(query), "" # Clear input box by returning empty string
|
| 104 |
|
| 105 |
+
|
| 106 |
+
def clear_history(db_choice, model_choice):
|
| 107 |
+
cb = initialize_cbfs(db_choice, model_choice) # Reinitialize cbfs to clear history
|
| 108 |
if cb is None: # Check if cbfs instance is None
|
| 109 |
return [], "" # No error message, simply clear the UI components
|
| 110 |
else:
|
|
|
|
| 158 |
)
|
| 159 |
|
| 160 |
# Define interactions for both submit button and Enter key
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
+
inp.submit(fn=chat_history, inputs=[inp, db_choice, model_choice], outputs=[output, inp])
|
| 163 |
+
button_submit.click(fn=chat_history, inputs=[inp, db_choice, model_choice], outputs=[output, inp])
|
| 164 |
+
button_clearhistory.click(fn=clear_history, inputs=[db_choice, model_choice], outputs=[output, inp])
|
| 165 |
|
| 166 |
|
| 167 |
# Launch the Gradio app
|