Spaces:
Running
Running
Bug fix
Browse files
app.py
CHANGED
|
@@ -7,21 +7,26 @@ import urllib.parse
|
|
| 7 |
|
| 8 |
st.title("Prem Chat UI")
|
| 9 |
|
| 10 |
-
if "api_key" not in st.session_state
|
| 11 |
api_key = st.text_input("Enter your API Key", type="password")
|
| 12 |
project_id = st.text_input("Enter your Project ID")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
st.session_state.api_key = api_key
|
| 16 |
-
st.session_state.project_id = int(project_id)
|
| 17 |
-
client = Prem(api_key=api_key)
|
| 18 |
-
st.rerun()
|
| 19 |
-
else:
|
| 20 |
-
st.warning("Please enter your Project ID correctly.")
|
| 21 |
-
st.stop()
|
| 22 |
-
else:
|
| 23 |
st.warning("Please enter your API key and Project ID to use the app.")
|
| 24 |
st.stop()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
else:
|
| 26 |
client = Prem(api_key=st.session_state.api_key)
|
| 27 |
|
|
@@ -65,9 +70,9 @@ def get_ai_response(messages):
|
|
| 65 |
st.button("Stop generating")
|
| 66 |
|
| 67 |
shown_message = ""
|
| 68 |
-
|
| 69 |
for chunk in stream:
|
| 70 |
-
if chunk.choices[0].delta
|
| 71 |
content = chunk.choices[0].delta["content"]
|
| 72 |
st.session_state.response += content
|
| 73 |
shown_message += content.replace("\n", " \n")
|
|
|
|
| 7 |
|
| 8 |
st.title("Prem Chat UI")
|
| 9 |
|
| 10 |
+
if "api_key" not in st.session_state or "project_id" not in st.session_state:
|
| 11 |
api_key = st.text_input("Enter your API Key", type="password")
|
| 12 |
project_id = st.text_input("Enter your Project ID")
|
| 13 |
+
|
| 14 |
+
if not api_key or not project_id:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
st.warning("Please enter your API key and Project ID to use the app.")
|
| 16 |
st.stop()
|
| 17 |
+
|
| 18 |
+
if not project_id.isdecimal():
|
| 19 |
+
st.warning("Please enter your Project ID correctly.")
|
| 20 |
+
st.stop()
|
| 21 |
+
|
| 22 |
+
if not api_key.isascii():
|
| 23 |
+
st.warning("Please enter your API key correctly.")
|
| 24 |
+
st.stop()
|
| 25 |
+
|
| 26 |
+
st.session_state.api_key = api_key
|
| 27 |
+
st.session_state.project_id = int(project_id)
|
| 28 |
+
client = Prem(api_key=api_key)
|
| 29 |
+
st.rerun()
|
| 30 |
else:
|
| 31 |
client = Prem(api_key=st.session_state.api_key)
|
| 32 |
|
|
|
|
| 70 |
st.button("Stop generating")
|
| 71 |
|
| 72 |
shown_message = ""
|
| 73 |
+
|
| 74 |
for chunk in stream:
|
| 75 |
+
if chunk.choices and chunk.choices[0].delta.get("content"):
|
| 76 |
content = chunk.choices[0].delta["content"]
|
| 77 |
st.session_state.response += content
|
| 78 |
shown_message += content.replace("\n", " \n")
|