Spaces:
Sleeping
Sleeping
Download app.py from pradipwasre/firstapp: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/pradipwasre/firstapp/resolve/main/app.py
- Command line
-
hf download hf://spaces/pradipwasre/firstapp/app.py
-
curl -L -o app.py https://huggingface.co/spaces/pradipwasre/firstapp/resolve/main/app.py
1.15 kB
| # import stremlit for web app framework | |
| import streamlit as st | |
| from langchain_openai import OpenAI | |
| from langchain_huggingface import HuggingFaceEndpoint | |
| # Setup API token | |
| #os.environ["HUGGINGFACEHUB_API_TOKEN"] = "sd" | |
| # Function to fetch response from the LLM model based on the user's question | |
| def get_ai_response(promt): | |
| # Initialize the languge model endpoint from hugging Face's hosted models | |
| llm_model = HuggingFaceEndpoint( | |
| repo_id = "mistralai/Mistral-7B-Instruct-v0.3" | |
| ) | |
| response = llm_model.invoke(promt) | |
| return response | |
| # set up the streamlit app UI | |
| st.set_page_config(page_title= "AI language Model Demo", | |
| page_icon = ":robot_face:") | |
| st.header("interactive languge Model") | |
| """ | |
| functionto get user input | |
| text from the streamlit text | |
| input field | |
| """ | |
| user_question = capture_input() | |
| if user_question: | |
| model_response = get_ai_response(user_question) | |
| # Botton to trigger response generation | |
| generate_button = st.button("generate response") | |
| # display model's response if the button is clicked | |
| if generate_button: | |
| st.subheader("models' response") | |
| st.write(model_response) |