carlotamdeluna commited on
Commit
8115330
1 Parent(s): 003bf66

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.llms import Ollama
2
+ import streamlit as st
3
+ from langchain.chains import LLMChain
4
+ from langchain.chains import ConversationChain
5
+ #importacipones adicionales
6
+ import streamlit as st
7
+ from langchain.chains import ConversationChain
8
+ from langchain.memory import ConversationBufferMemory
9
+ from langchain.chains import ConversationChain
10
+ from langchain.prompts import PromptTemplate
11
+
12
+ from langchain.chains.conversation.memory import ConversationEntityMemory
13
+ from langchain.chains.conversation.prompt import ENTITY_MEMORY_CONVERSATION_TEMPLATE
14
+ from langchain_community.llms import HuggingFaceEndpoint
15
+ import os
16
+ from langchain.llms import Ollama
17
+
18
+
19
+ st.set_page_config(page_title= "bot", layout="wide")
20
+
21
+ #Interfaz
22
+ st.title("Maqueta")
23
+
24
+
25
+
26
+ #template
27
+
28
+
29
+
30
+
31
+ #llm
32
+
33
+ llm = HuggingFaceEndpoint(repo_id='mistralai/Mistral-7B-v0.1',
34
+ max_length=128,
35
+ temperature=0.5)
36
+
37
+ #memory
38
+
39
+
40
+
41
+ conversation_buf = ConversationChain(llm = llm,
42
+ memory = ConversationBufferMemory(),
43
+ verbose = True)
44
+
45
+
46
+
47
+ if "generated" not in st.session_state:
48
+ st.session_state["generated"] = []
49
+ if "past" not in st.session_state:
50
+ st.session_state["past"] = []
51
+ if "input" not in st.session_state:
52
+ st.session_state["input"] = ""
53
+ if "stored_session" not in st.session_state:
54
+ st.session_state["stored_session"] = []
55
+
56
+
57
+ def get_text():
58
+ """
59
+ Get the user input text.
60
+
61
+ Returns:
62
+ (str): The text entered by the user
63
+ """
64
+ input_text = st.text_input("You: ", st.session_state["input"], key="input",
65
+ placeholder="Your AI assistant here! Ask me anything ...",
66
+ label_visibility='hidden')
67
+ return input_text
68
+
69
+ user_input = get_text()
70
+
71
+ if 'entity memory' not in st.session_state:
72
+ st.session_state.entity_memory = ConversationEntityMemory(llm = llm,k=10)
73
+
74
+ Conversation = ConversationChain(llm = llm,
75
+ prompt= ENTITY_MEMORY_CONVERSATION_TEMPLATE,
76
+ memory = st.session_state.entity_memory)
77
+
78
+
79
+ while True:
80
+
81
+
82
+ output = Conversation.run(input=user_input)
83
+ st.session_state.past.append(user_input)
84
+ st.session_state.generated.append(output)
85
+