Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import requests | |
| import json | |
| def query_api(message, system_prompt): | |
| url = "https://cc15-115-112-111-186.ngrok-free.app/v1/chat/completions" | |
| headers = {"Content-Type": "application/json"} | |
| payload = { | |
| "model": "deepseek-r1-distill-llama-70b", | |
| "messages": [ | |
| {"role": "system", "content": system_prompt}, | |
| {"role": "user", "content": message} | |
| ], | |
| "temperature": 0.7, | |
| "max_tokens": 300, | |
| "stream": False | |
| } | |
| response = requests.post(url, headers=headers, json=payload) | |
| return response.json() | |
| # Streamlit UI Setup | |
| st.set_page_config(page_title="AI Chatbot", layout="centered") | |
| st.title("🤖 AI Chatbot") | |
| st.write("Talk to an AI coding assistant!") | |
| # Sidebar for system prompt | |
| st.sidebar.header("Settings") | |
| system_prompt = st.sidebar.text_area("System Prompt", "You are a helpful coding assistant.") | |
| if "chat_history" not in st.session_state: | |
| st.session_state.chat_history = [] | |
| # Display chat history | |
| for chat in st.session_state.chat_history: | |
| with st.chat_message(chat["role"]): | |
| st.markdown(chat["content"]) | |
| # User input field | |
| user_input = st.chat_input("Type your message here...") | |
| if user_input: | |
| st.session_state.chat_history.append({"role": "user", "content": user_input}) | |
| with st.chat_message("user"): | |
| st.markdown(user_input) | |
| with st.chat_message("assistant"): | |
| response_data = query_api(user_input, system_prompt) | |
| response_text = response_data["choices"][0]["message"]["content"] | |
| st.markdown(response_text) | |
| st.session_state.chat_history.append({"role": "assistant", "content": response_text}) | |