Create app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445import streamlit as stimport requestsimport json
# Streamlit appst.title("OpenRouter AI Chat App")st.write("Ask any question and get a response from the DeepSeek model!")
# Input for user questionuser_input = st.text_area("Enter your question:", height=150)
# Button to submit the questionif st.button("Get Response"): if user_input.strip(): st.write("Processing your question...") try: # API request response = requests.post( url="https://openrouter.ai/api/v1/chat/completions", headers={ "Authorization": f"Bearer {st.secrets['sk-or-v1-667a54ccc7364be8d56e257d4ac294cc813af8a9e696e19f6d7bed8521e1f6b']}", # Securely store API key in Streamlit secrets "Content-Type": "application/json", }, data=json.dumps({ "model": "deepseek/deepseek-v3-base:free", "messages": [ { "role": "user", "content": user_input, } ], }), )
# Handle the response if response.status_code == 200: result = response.json() st.markdown("### Response:") st.markdown(result["choices"][0]["message"]["content"]) else: st.error(f"Error: {response.status_code} - {response.text}") except Exception as e: st.error(f"An error occurred: {e}") else: st.warning("Please enter a question.")app.pyAdded+45