Spaces:
Sleeping
Sleeping
Download src/streamlit_app.py from zypchn/SimplePythonHelper: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/zypchn/SimplePythonHelper/resolve/7ccf27f64509085de51daeb3fc14131ec526d1d5/src/streamlit_app.py
- Command line
-
hf download hf://spaces/zypchn/SimplePythonHelper@7ccf27f64509085de51daeb3fc14131ec526d1d5/src/streamlit_app.py
-
curl -L -o streamlit_app.py https://huggingface.co/spaces/zypchn/SimplePythonHelper/resolve/7ccf27f64509085de51daeb3fc14131ec526d1d5/src/streamlit_app.py
1.1 kB
| ### Q&A Chatbot ### | |
| import os | |
| import streamlit as st | |
| from langchain_openai import ChatOpenAI | |
| from langchain.prompts.chat import ChatPromptTemplate | |
| ## Load Anthropic model and get response | |
| def get_openai_response(question, api_key): | |
| system_template = "You are a helpful coder assistant. When the user asks a question, your task is to write simple Python codes." | |
| user_template = "{question}" | |
| chat_prompt = ChatPromptTemplate.from_messages([ | |
| ("system", system_template), | |
| ("human", user_template) | |
| ]) | |
| chat_llm = ChatOpenAI(temperature=0.5, api_key=api_key) | |
| chain = chat_prompt | chat_llm | |
| return chain.invoke(question).content | |
| ## Initialize Streamlit app | |
| st.set_page_config(page_title="Simple Langchain App") | |
| st.header("Coder Q&A Demo") | |
| OPENAI_API_KEY = st.text_input("OpenAI API Key: ", type="password") | |
| input = st.text_input("Input: ", key=input) | |
| submit = st.button("Ask your question...") | |
| if submit: | |
| response = get_openai_response(input, api_key=OPENAI_API_KEY) | |
| st.subheader("The response is:") | |
| st.write(response) |