Spaces:
Sleeping
Sleeping
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} | |
``` | |
```` | |
""" | |
) |