Spaces:
Sleeping
Sleeping
File size: 978 Bytes
b1229df 8943693 9ec7f06 8943693 9ec7f06 8943693 9ec7f06 8943693 86b5c4d 8943693 9ec7f06 8943693 37e3916 c743029 37e3916 9ec7f06 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import os
import openai
import streamlit as st
openai.api_key = os.getenv("OPENAI_API_KEY")
temperature = 0
prompt = st.text_area("Prompt")
if st.button("Submit"):
st.markdown("----")
res_box = st.empty()
share_box = st.empty()
content = []
for chunk in openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=temperature,
messages=[{"role": "user", "content": prompt}],
stream=True,
):
chunk_content = chunk["choices"][0].get("delta", {}).get("content")
if chunk_content is not None:
content.append(chunk_content)
result = "".join(content).strip()
res_box.write(result)
st.markdown("----")
st.subheader("共有用")
result = "".join(content).strip()
share_box.markdown(
f"""
````
### Prompt
```
{prompt}
```
### Output
```
{result}
```
````
"""
) |