Spaces:
Runtime error
Runtime error
Update streamlit_app.py
Browse files- streamlit_app.py +7 -7
streamlit_app.py
CHANGED
|
@@ -9,7 +9,7 @@ st.write("Paste your Python code below and get a detailed explanation using Open
|
|
| 9 |
|
| 10 |
code_input = st.text_area("Paste Python Code", height=200)
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
if st.button("Explain"):
|
| 15 |
if not openai_api_key:
|
|
@@ -18,12 +18,12 @@ if st.button("Explain"):
|
|
| 18 |
with st.spinner("Asking GPT-3.5..."):
|
| 19 |
prompt = f"Explain the following Python function step-by-step in plain English:\n\n{code_input.strip()}"
|
| 20 |
try:
|
| 21 |
-
response =
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
explanation = response.choices[0].message["content"].strip()
|
| 28 |
st.subheader("✅ Explanation")
|
| 29 |
st.write(explanation)
|
|
|
|
| 9 |
|
| 10 |
code_input = st.text_area("Paste Python Code", height=200)
|
| 11 |
|
| 12 |
+
client = openai.OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
|
| 13 |
|
| 14 |
if st.button("Explain"):
|
| 15 |
if not openai_api_key:
|
|
|
|
| 18 |
with st.spinner("Asking GPT-3.5..."):
|
| 19 |
prompt = f"Explain the following Python function step-by-step in plain English:\n\n{code_input.strip()}"
|
| 20 |
try:
|
| 21 |
+
response = client.chat.completions.create(
|
| 22 |
+
model="gpt-3.5-turbo",
|
| 23 |
+
messages=[{"role": "user", "content": prompt}],
|
| 24 |
+
max_tokens=512,
|
| 25 |
+
temperature=0.5,
|
| 26 |
+
)
|
| 27 |
explanation = response.choices[0].message["content"].strip()
|
| 28 |
st.subheader("✅ Explanation")
|
| 29 |
st.write(explanation)
|