I am new to Streamlit. Am using the code below to get data from snowflake replicate API and everything is working fine
import streamlit as st
import numpy as np
import pandas as pd
import replicate
import os
st.write("# Welcome to Streamlit! ??")
#Set the REPLICATE_API_TOKEN environment variable
os.environ["REPLICATE_API_TOKEN"] = "my token goes here"
for event in replicate.stream(
"snowflake/snowflake-arctic-instruct",
input={
"top_k": 50,
"top_p": 0.9,
"prompt": "Define food",
"temperature": 0.2,
"max_new_tokens": 512,
"min_new_tokens": 0,
"stop_sequences": "<|im_end|>",
"prompt_template": "<|im_start|>system\nYou're a helpful assistant<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n\n<|im_start|>assistant\n",
"presence_penalty": 1.15,
"frequency_penalty": 0.2
},
):
eventx = event
st.write(event)
print(str(event), end="")
Here is my issue. I need to get event result data to be passed to form input value and to session_state. I have tried this code below
if event:
st.text_input("Your namex", key="namex", value=eventx)
# You can access the data at any point with:
st.session_state.eventx
But it throw error
**DuplicateWidgetID**: There are multiple widgets with the same `key='namex'`.
To fix this, please make sure that the `key` argument is unique for each widget you create.
Traceback:
File “C:\python_app2\pages\page3.py”, line 39, in
st.text_input(“Your namex”, key=“namex”, value=event)
Here is the full code
import streamlit as st
import numpy as np
import pandas as pd
import replicate
import os
st.write("# Welcome to Streamlit! ??")
#Set the REPLICATE_API_TOKEN environment variable
os.environ["REPLICATE_API_TOKEN"] = "my token goes here"
for event in replicate.stream(
"snowflake/snowflake-arctic-instruct",
input={
"top_k": 50,
"top_p": 0.9,
"prompt": "Define food",
"temperature": 0.2,
"max_new_tokens": 512,
"min_new_tokens": 0,
"stop_sequences": "<|im_end|>",
"prompt_template": "<|im_start|>system\nYou're a helpful assistant<|im_end|>\n<|im_start|>user\n{prompt}<|im_end|>\n\n<|im_start|>assistant\n",
"presence_penalty": 1.15,
"frequency_penalty": 0.2
},
):
eventx = event
st.write(event)
print(str(event), end="")
if event:
st.text_input("Your namex", key="namex", value=eventx)
# You can access the data at any point with:
st.session_state.eventx
Please I need help…