Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,7 @@ from llama_cpp_agent.chat_history import BasicChatHistory
|
|
9 |
from llama_cpp_agent.chat_history.messages import Roles
|
10 |
import cv2
|
11 |
|
12 |
-
#
|
13 |
huggingface_token = os.environ.get('HF_TOKEN')
|
14 |
download_models(huggingface_token)
|
15 |
|
@@ -19,9 +19,8 @@ documents_paths = {
|
|
19 |
'payment': 'data/payment'
|
20 |
}
|
21 |
|
22 |
-
#
|
23 |
backend = Backend()
|
24 |
-
|
25 |
cv2.setNumThreads(1)
|
26 |
|
27 |
@spaces.GPU(duration=20)
|
@@ -37,7 +36,7 @@ def respond(
|
|
37 |
repeat_penalty,
|
38 |
selected_topic
|
39 |
):
|
40 |
-
chat_template = MessagesFormatterType.
|
41 |
|
42 |
print("HISTORY SO FAR ", history)
|
43 |
print("Selected topic:", selected_topic)
|
@@ -77,7 +76,7 @@ def respond(
|
|
77 |
|
78 |
messages = BasicChatHistory()
|
79 |
|
80 |
-
#
|
81 |
for user_msg, assistant_msg in history:
|
82 |
messages.add_message({'role': Roles.user, 'content': user_msg})
|
83 |
messages.add_message({'role': Roles.assistant, 'content': assistant_msg})
|
@@ -98,6 +97,9 @@ def respond(
|
|
98 |
except Exception as e:
|
99 |
yield history + [[message, f"Error during response generation: {str(e)}"]]
|
100 |
|
|
|
|
|
|
|
101 |
def select_topic(topic):
|
102 |
return gr.update(visible=True), topic, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
|
103 |
|
@@ -113,6 +115,7 @@ with gr.Blocks(css="""
|
|
113 |
blockchain_btn = gr.Button("π Blockchain", scale=1)
|
114 |
metaverse_btn = gr.Button("π Metaverse", scale=1)
|
115 |
payment_btn = gr.Button("π³ Payment", scale=1)
|
|
|
116 |
|
117 |
selected_topic = gr.State(value="")
|
118 |
|
@@ -156,6 +159,8 @@ with gr.Blocks(css="""
|
|
156 |
blockchain_btn.click(lambda: select_topic("blockchain"), inputs=None, outputs=[chatbot, selected_topic, blockchain_btn, metaverse_btn, payment_btn])
|
157 |
metaverse_btn.click(lambda: select_topic("metaverse"), inputs=None, outputs=[chatbot, selected_topic, blockchain_btn, metaverse_btn, payment_btn])
|
158 |
payment_btn.click(lambda: select_topic("payment"), inputs=None, outputs=[chatbot, selected_topic, blockchain_btn, metaverse_btn, payment_btn])
|
|
|
|
|
159 |
|
160 |
submit_btn.click(
|
161 |
respond,
|
|
|
9 |
from llama_cpp_agent.chat_history.messages import Roles
|
10 |
import cv2
|
11 |
|
12 |
+
# Get the models
|
13 |
huggingface_token = os.environ.get('HF_TOKEN')
|
14 |
download_models(huggingface_token)
|
15 |
|
|
|
19 |
'payment': 'data/payment'
|
20 |
}
|
21 |
|
22 |
+
# Initialize backend
|
23 |
backend = Backend()
|
|
|
24 |
cv2.setNumThreads(1)
|
25 |
|
26 |
@spaces.GPU(duration=20)
|
|
|
36 |
repeat_penalty,
|
37 |
selected_topic
|
38 |
):
|
39 |
+
chat_template = MessagesFormatterType.DEFAULT # Changed to default mode
|
40 |
|
41 |
print("HISTORY SO FAR ", history)
|
42 |
print("Selected topic:", selected_topic)
|
|
|
76 |
|
77 |
messages = BasicChatHistory()
|
78 |
|
79 |
+
# Add user and assistant messages to the history
|
80 |
for user_msg, assistant_msg in history:
|
81 |
messages.add_message({'role': Roles.user, 'content': user_msg})
|
82 |
messages.add_message({'role': Roles.assistant, 'content': assistant_msg})
|
|
|
97 |
except Exception as e:
|
98 |
yield history + [[message, f"Error during response generation: {str(e)}"]]
|
99 |
|
100 |
+
def reset_conversation():
|
101 |
+
return [], "", gr.update(visible=False), gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)
|
102 |
+
|
103 |
def select_topic(topic):
|
104 |
return gr.update(visible=True), topic, gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)
|
105 |
|
|
|
115 |
blockchain_btn = gr.Button("π Blockchain", scale=1)
|
116 |
metaverse_btn = gr.Button("π Metaverse", scale=1)
|
117 |
payment_btn = gr.Button("π³ Payment", scale=1)
|
118 |
+
reset_btn = gr.Button("π Reset", scale=1) # Reset button
|
119 |
|
120 |
selected_topic = gr.State(value="")
|
121 |
|
|
|
159 |
blockchain_btn.click(lambda: select_topic("blockchain"), inputs=None, outputs=[chatbot, selected_topic, blockchain_btn, metaverse_btn, payment_btn])
|
160 |
metaverse_btn.click(lambda: select_topic("metaverse"), inputs=None, outputs=[chatbot, selected_topic, blockchain_btn, metaverse_btn, payment_btn])
|
161 |
payment_btn.click(lambda: select_topic("payment"), inputs=None, outputs=[chatbot, selected_topic, blockchain_btn, metaverse_btn, payment_btn])
|
162 |
+
|
163 |
+
reset_btn.click(reset_conversation, inputs=None, outputs=[chatbot, selected_topic, blockchain_btn, metaverse_btn, payment_btn]) # Connect reset button
|
164 |
|
165 |
submit_btn.click(
|
166 |
respond,
|