Spaces:
Sleeping
Sleeping
File size: 2,456 Bytes
efe92e5 538620b 61d4bed 8115330 538620b 8115330 5cddbe9 8115330 370fee9 9293988 8115330 6b54436 8115330 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
import subprocess
# Instalar un paquete utilizando pip desde Python
subprocess.check_call(["pip", "install", "langchain_community","langchain"])
import streamlit as st
from langchain.chains import LLMChain
from langchain.chains import ConversationChain
#importacipones adicionales
import streamlit as st
from langchain.chains import ConversationChain
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationChain
from langchain.prompts import PromptTemplate
from langchain.chains.conversation.memory import ConversationEntityMemory
from langchain.chains.conversation.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
from langchain_community.llms import HuggingFaceEndpoint
import os
st.set_page_config(page_title= "bot", layout="wide")
#Interfaz
st.title("Maqueta")
#template
#llm
llm = HuggingFaceEndpoint(repo_id='mistralai/Mistral-7B-v0.1',
max_length=128,
temperature=0.5,
higgingfacehub_api_token = os.environ["HUGGINGFACEHUB_API_TOKEN"])
#memory
conversation_buf = ConversationChain(llm = llm,
memory = ConversationBufferMemory(),
verbose = True)
if "generated" not in st.session_state:
st.session_state["generated"] = []
if "past" not in st.session_state:
st.session_state["past"] = []
if "input" not in st.session_state:
st.session_state["input"] = ""
if "stored_session" not in st.session_state:
st.session_state["stored_session"] = []
def get_text():
"""
Get the user input text.
Returns:
(str): The text entered by the user
"""
input_text = st.text_input("You: ", st.session_state["input"], key="input",
placeholder="Your AI assistant here! Ask me anything ...",
label_visibility='hidden')
return input_text
user_input = get_text()
if 'entity memory' not in st.session_state:
st.session_state.entity_memory = ConversationEntityMemory(llm = llm,k=10)
Conversation = ConversationChain(llm = llm,
prompt= ENTITY_MEMORY_CONVERSATION_TEMPLATE,
memory = st.session_state.entity_memory)
submit = st.button("Generate")
while submit:
output = Conversation.run(input=user_input)
st.session_state.past.append(user_input)
st.session_state.generated.append(output)
|