Spaces:
Sleeping
Sleeping
File size: 734 Bytes
b1229df 8943693 280a867 8943693 86b5c4d 8943693 37e3916 8943693 280a867 8943693 |
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 |
import os
import openai
import streamlit as st
openai.api_key = os.getenv("OPENAI_API_KEY")
temperature = 0
input = st.text_input("Input")
if st.button("Submit", type="primary"):
st.markdown("----")
res_box = st.empty()
content = []
for chunk in openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=temperature,
messages=[{"role": "user", "content": input}],
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()
result = result.replace("\n", "")
res_box.markdown(result)
st.markdown("----") |