Spaces:
Sleeping
Sleeping
Jesus Sanchez commited on
Commit ·
1d53447
1
Parent(s): 489e1e3
using text input
Browse files
app.py
CHANGED
|
@@ -164,5 +164,6 @@ What trades did client {client} do in May 2022
|
|
| 164 |
with st.sidebar:
|
| 165 |
st.markdown(sidebar_text)
|
| 166 |
|
|
|
|
| 167 |
with st.container():
|
| 168 |
-
chat.get_input(get_response, llm)
|
|
|
|
| 164 |
with st.sidebar:
|
| 165 |
st.markdown(sidebar_text)
|
| 166 |
|
| 167 |
+
prompt = chat.get_promt("Ask IDF Anything")
|
| 168 |
with st.container():
|
| 169 |
+
chat.get_input(prompt, get_response, llm)
|
chat.py
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from typing import Callable
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
RESPONSE_LABEL = 'chat_response'
|
| 7 |
-
PROMPT_LABEL = '
|
|
|
|
| 8 |
|
| 9 |
class Chat:
|
|
|
|
| 10 |
def __init__(self):
|
| 11 |
if RESPONSE_LABEL not in st.session_state:
|
| 12 |
st.session_state[RESPONSE_LABEL] = []
|
|
@@ -14,7 +17,18 @@ class Chat:
|
|
| 14 |
if PROMPT_LABEL not in st.session_state:
|
| 15 |
st.session_state[PROMPT_LABEL] = []
|
| 16 |
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
process_prompt(promt: str, *args) -> tuple(Any, Callable)
|
| 20 |
callback to process the chat promt, it takes the promt for input
|
|
@@ -30,7 +44,7 @@ class Chat:
|
|
| 30 |
on_render(response)
|
| 31 |
|
| 32 |
# Compute prompt
|
| 33 |
-
if prompt:
|
| 34 |
st.session_state[PROMPT_LABEL].append(prompt)
|
| 35 |
(response, on_render) = process_prompt(prompt, *args)
|
| 36 |
st.session_state[RESPONSE_LABEL].append((response, on_render))
|
|
|
|
| 1 |
+
from sqlalchemy import label
|
| 2 |
import streamlit as st
|
| 3 |
from typing import Callable
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
RESPONSE_LABEL = 'chat_response'
|
| 8 |
+
PROMPT_LABEL = 'chat_prompt'
|
| 9 |
+
TEXT_INPUT_LABEL = "chat_input"
|
| 10 |
|
| 11 |
class Chat:
|
| 12 |
+
|
| 13 |
def __init__(self):
|
| 14 |
if RESPONSE_LABEL not in st.session_state:
|
| 15 |
st.session_state[RESPONSE_LABEL] = []
|
|
|
|
| 17 |
if PROMPT_LABEL not in st.session_state:
|
| 18 |
st.session_state[PROMPT_LABEL] = []
|
| 19 |
|
| 20 |
+
if TEXT_INPUT_LABEL not in st.session_state:
|
| 21 |
+
st.session_state[TEXT_INPUT_LABEL] = ''
|
| 22 |
+
|
| 23 |
+
def get_promt(self, placeholder: str):
|
| 24 |
+
return st.text_input(
|
| 25 |
+
label="ChatIDF",
|
| 26 |
+
placeholder=placeholder,
|
| 27 |
+
key="chat_widget",
|
| 28 |
+
)
|
| 29 |
+
# return st.chat_input(placeholder=placeholder)
|
| 30 |
+
|
| 31 |
+
def get_input(self, prompt: str, process_prompt: Callable, *args):
|
| 32 |
"""
|
| 33 |
process_prompt(promt: str, *args) -> tuple(Any, Callable)
|
| 34 |
callback to process the chat promt, it takes the promt for input
|
|
|
|
| 44 |
on_render(response)
|
| 45 |
|
| 46 |
# Compute prompt
|
| 47 |
+
if prompt:
|
| 48 |
st.session_state[PROMPT_LABEL].append(prompt)
|
| 49 |
(response, on_render) = process_prompt(prompt, *args)
|
| 50 |
st.session_state[RESPONSE_LABEL].append((response, on_render))
|