Spaces:
Sleeping
Sleeping
#Hello! It seems like you want to import the Streamlit library in Python. Streamlit is a powerful open-source framework used for building web applications with interactive data visualizations and machine learning models. To import Streamlit, you'll need to ensure that you have it installed in your Python environment. | |
#Once you have Streamlit installed, you can import it into your Python script using the import statement, | |
import streamlit as st | |
from langchain import HuggingFaceHub # Correct import for Hugging Face | |
# Set your Hugging Face API token | |
HUGGINGFACE_API_TOKEN = "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" | |
# Function to return the response from Hugging Face model | |
def load_answer(question): | |
# Initialize the Hugging Face model | |
llm = HuggingFaceHub( | |
repo_id="mistralai/Mistral-7B-Instruct-v0.3", # Specify the Hugging Face model | |
huggingfacehub_api_token=HUGGINGFACE_API_TOKEN, # Pass your API token | |
model_kwargs={"temperature": 0} # Optional: Control response randomness | |
) | |
# Call the model with the user's question and get the response | |
answer = llm(question) | |
return answer | |
# Streamlit App UI starts here | |
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:") | |
st.header("LangChain Demo") | |
# Function to get user input | |
def get_text(): | |
input_text = st.text_input("You: ", key="input") | |
return input_text | |
# Get user input | |
user_input = get_text() | |
# Create a button for generating the response | |
submit = st.button('Generate') | |
# If generate button is clicked and user input is not empty | |
if submit and user_input: | |
response = load_answer(user_input) | |
st.subheader("Answer:") | |
st.write(response) | |
elif submit: | |
st.warning("Please enter a question.") # Warning for empty input | |