Spaces:
Runtime error
Runtime error
| from shiny import App, ui, render, reactive | |
| import subprocess | |
| app_ui = ui.page_sidebar( | |
| ui.sidebar( | |
| ui.input_action_button("install_ollama", "Install Ollama"), | |
| ui.input_action_button("run_ollama", "Run GPT-OSS:20B"), | |
| ), | |
| ui.panel_main( | |
| ui.input_text_area("user_message", "Type your message here...", height="100px"), | |
| ui.input_action_button("send", "Send"), | |
| ui.output_text_verbatim("chat_history"), | |
| ) | |
| ) | |
| def server(input, output, session): | |
| chat_history = reactive.Value("") | |
| def chat_history(): | |
| return chat_history() | |
| def install_ollama(): | |
| try: | |
| subprocess.run(["curl", "-fsSL", "https://ollama.com/install.sh", "|", "sh"], check=True, shell=True) | |
| chat_history.set(chat_history() + "\nOllama installed successfully.") | |
| except subprocess.CalledProcessError as e: | |
| chat_history.set(chat_history() + f"\nError installing Ollama: {e}") | |
| def run_ollama_model(): | |
| try: | |
| subprocess.Popen(["ollama", "run", "gpt-oss:20b"]) | |
| chat_history.set(chat_history() + "\nRunning GPT-OSS:20B model.") | |
| except Exception as e: | |
| chat_history.set(chat_history() + f"\nError running model: {e}") | |
| def send_message(): | |
| user_message = input.user_message() | |
| if user_message: | |
| chat_history.set(chat_history() + f"\nYou: {user_message}") | |
| # Here you would typically send the message to the chat server and get a response | |
| # For now, we'll just echo the message | |
| chat_history.set(chat_history() + f"\nBot: {user_message}") | |
| app = App(app_ui, server) | |