salomonsky commited on
Commit
5100159
1 Parent(s): 762ff52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -16
app.py CHANGED
@@ -1,8 +1,8 @@
1
- import os
2
  import streamlit as st
3
  from huggingface_hub import InferenceClient
4
 
5
- st.title("MAYA 3.0 CHATBOT IA")
 
6
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
7
  conversation_history = []
8
 
@@ -33,22 +33,44 @@ def format_prompt(message, history):
33
  prompt += f"[INST] {message} [/INST]"
34
  return prompt
35
 
36
- with st.container():
37
- user_input = st.text_input("Usuario:")
38
- system_prompt = st.text_input("System Prompt:")
39
- temperature = st.slider("Temperatura", 0.0, 1.0, 0.9)
40
- max_new_tokens = st.slider("N煤mero m谩ximo de nuevos tokens", 0, 2048, 2048)
41
- top_p = st.slider("Top-p (nucleus sampling)", 0.0, 1.0, 0.95)
42
- repetition_penalty = st.slider("Penalizaci贸n por repetici贸n", 1.0, 2.0, 1.0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
  if st.button("Enviar"):
45
- if user_input:
46
  conversation_history.append(("user", user_input))
47
  bot_response = generate_response(user_input, conversation_history, system_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
48
- conversation_history.append(("bot", bot_response))
 
 
 
 
 
49
 
50
- for role, message in conversation_history:
51
- if role == "user":
52
- st.text(f"Usuario: {message}")
53
- elif role == "bot":
54
- st.text(f"Chatbot: {message}")
 
 
1
  import streamlit as st
2
  from huggingface_hub import InferenceClient
3
 
4
+ st.set_page_config(page_title="MAYA 3.0 CHATBOT IA", page_icon=":robot_face:")
5
+
6
  client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1")
7
  conversation_history = []
8
 
 
33
  prompt += f"[INST] {message} [/INST]"
34
  return prompt
35
 
36
+ def validate_input(user_input, system_prompt):
37
+ if not user_input:
38
+ st.warning("Por favor ingrese un mensaje.")
39
+ return False
40
+ if not system_prompt:
41
+ st.warning("Por favor ingrese un prompt del sistema.")
42
+ return False
43
+ return True
44
+
45
+ def display_help():
46
+ st.write("Tambi茅n puede ingresar un prompt del sistema para guiar la generaci贸n de texto.")
47
+
48
+ def display_conversation_history(history):
49
+ for role, message in history:
50
+ if role == "user":
51
+ st.text(f"Usuario: {message}")
52
+ elif role == "bot":
53
+ st.text(f"Chatbot: {message}")
54
+
55
+ def main():
56
+ st.title("MAYA 3.0 CHATBOT IA")
57
+ user_input = st.text_input("Escribe tu mensaje")
58
+ system_prompt = st.text_input("Ingrese el prompt del sistema")
59
+ temperature = st.hidden_selectbox("Temperatura", options=list(range(1, 11)))
60
+ max_new_tokens = st.hidden_selectbox("N煤mero m谩ximo de nuevos tokens", options=list(range(1, 2049)))
61
+ top_p = st.hidden_selectbox("Top-p (nucleus sampling)", options=list(range(1, 11)))
62
+ repetition_penalty = st.hidden_selectbox("Penalizaci贸n por repetici贸n", options=list(range(1, 2)))
63
 
64
  if st.button("Enviar"):
65
+ if validate_input(user_input, system_prompt):
66
  conversation_history.append(("user", user_input))
67
  bot_response = generate_response(user_input, conversation_history, system_prompt, temperature, max_new_tokens, top_p, repetition_penalty)
68
+ conversation_history.append(("bot", bot_response)
69
+
70
+ if st.button("Ayuda"):
71
+ display_help()
72
+
73
+ display_conversation_history(conversation_history)
74
 
75
+ if __name__ == "__main__":
76
+ main()