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 prompt: | |
output_box = st.empty() | |
share_box = st.empty() | |
content = [] | |
for chunk in openai.ChatCompletion.create( | |
model="gpt-4o-mini", | |
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) | |
output = "".join(content).strip() | |
output_box.markdown(output) | |
output = "".join(content).strip() | |
share_box.markdown( | |
f""" | |
```` | |
**Prompt:** | |
``` | |
{prompt} | |
``` | |
**Output:** | |
``` | |
{output} | |
``` | |
```` | |
""" | |
) |