Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ from datetime import datetime
|
|
5 |
from typing import Literal
|
6 |
import os
|
7 |
import importlib
|
8 |
-
from llm_handler import send_to_llm
|
9 |
from main import generate_data, PROMPT_1
|
10 |
from topics import TOPICS
|
11 |
from system_messages import SYSTEM_MESSAGES_VODALUS
|
@@ -264,8 +264,13 @@ def save_dataset_config(system_messages, prompt_1, topics):
|
|
264 |
return "Dataset configuration saved successfully"
|
265 |
|
266 |
# Modify the chat_with_llm function to use Gradio's built-in async capabilities
|
267 |
-
def chat_with_llm(message, history, selected_llm):
|
268 |
try:
|
|
|
|
|
|
|
|
|
|
|
269 |
msg_list = [{"role": "system", "content": "You are an AI assistant helping with dataset annotation and quality checking."}]
|
270 |
for h in history:
|
271 |
msg_list.append({"role": "user", "content": h[0]})
|
@@ -407,7 +412,9 @@ with demo:
|
|
407 |
|
408 |
with gr.Column(scale=1):
|
409 |
gr.Markdown("## AI Assistant")
|
410 |
-
selected_llm = gr.Radio(["local-model", "anything-llm"], label="Select LLM", value="local-model")
|
|
|
|
|
411 |
chatbot = gr.Chatbot(height=600)
|
412 |
msg = gr.Textbox(label="Chat with AI Assistant")
|
413 |
clear = gr.Button("Clear")
|
@@ -507,7 +514,7 @@ with demo:
|
|
507 |
outputs=[generation_status, generation_output]
|
508 |
)
|
509 |
|
510 |
-
msg.submit(chat_with_llm, [msg, chatbot, selected_llm], [chatbot])
|
511 |
clear.click(lambda: None, None, chatbot, queue=False)
|
512 |
|
513 |
# Update chat context when navigating rows or loading dataset
|
@@ -518,5 +525,11 @@ with demo:
|
|
518 |
outputs=[chatbot]
|
519 |
)
|
520 |
|
|
|
|
|
|
|
|
|
|
|
521 |
if __name__ == "__main__":
|
522 |
demo.launch(share=True)
|
|
|
|
5 |
from typing import Literal
|
6 |
import os
|
7 |
import importlib
|
8 |
+
from llm_handler import send_to_llm, set_local_model_base_url, set_anything_llm_workspace
|
9 |
from main import generate_data, PROMPT_1
|
10 |
from topics import TOPICS
|
11 |
from system_messages import SYSTEM_MESSAGES_VODALUS
|
|
|
264 |
return "Dataset configuration saved successfully"
|
265 |
|
266 |
# Modify the chat_with_llm function to use Gradio's built-in async capabilities
|
267 |
+
def chat_with_llm(message, history, selected_llm, base_url, anything_llm_workspace):
|
268 |
try:
|
269 |
+
if selected_llm == "local-model":
|
270 |
+
set_local_model_base_url(base_url)
|
271 |
+
elif selected_llm == "anything-llm":
|
272 |
+
set_anything_llm_workspace(anything_llm_workspace)
|
273 |
+
|
274 |
msg_list = [{"role": "system", "content": "You are an AI assistant helping with dataset annotation and quality checking."}]
|
275 |
for h in history:
|
276 |
msg_list.append({"role": "user", "content": h[0]})
|
|
|
412 |
|
413 |
with gr.Column(scale=1):
|
414 |
gr.Markdown("## AI Assistant")
|
415 |
+
selected_llm = gr.Radio(["local-model", "anything-llm", "llamacpp"], label="Select LLM", value="local-model")
|
416 |
+
base_url = gr.Textbox(label="Base URL for local-model", value="http://localhost:11434/v1", visible=False)
|
417 |
+
anything_llm_workspace = gr.Textbox(label="AnythingLLM Workspace", value="<input-workspace-name-here>", visible=False)
|
418 |
chatbot = gr.Chatbot(height=600)
|
419 |
msg = gr.Textbox(label="Chat with AI Assistant")
|
420 |
clear = gr.Button("Clear")
|
|
|
514 |
outputs=[generation_status, generation_output]
|
515 |
)
|
516 |
|
517 |
+
msg.submit(chat_with_llm, [msg, chatbot, selected_llm, base_url, anything_llm_workspace], [chatbot])
|
518 |
clear.click(lambda: None, None, chatbot, queue=False)
|
519 |
|
520 |
# Update chat context when navigating rows or loading dataset
|
|
|
525 |
outputs=[chatbot]
|
526 |
)
|
527 |
|
528 |
+
def toggle_input_visibility(llm):
|
529 |
+
return gr.update(visible=llm == "local-model"), gr.update(visible=llm == "anything-llm")
|
530 |
+
|
531 |
+
selected_llm.change(toggle_input_visibility, inputs=[selected_llm], outputs=[base_url, anything_llm_workspace])
|
532 |
+
|
533 |
if __name__ == "__main__":
|
534 |
demo.launch(share=True)
|
535 |
+
|