CoolFace
Apppublic

Daneeno/Problem_Solver-2

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py32 linesDownload Raw Back to root
1import streamlit as st2import openai3 4# Set your OpenAI API key here (you can hide it using secrets in Hugging Face Spaces)5openai.api_key = st.secrets["OPENAI_API_KEY"]6 7st.set_page_config(page_title="Problem Solver", layout="centered")8 9st.title("🧠 AI Problem Solver")10st.write("Enter any problem below, and I’ll provide the best solution I can!")11 12# User input13problem = st.text_area("Describe your problem:")14 15if st.button("Get Solution"):16    if problem.strip() == "":17        st.warning("Please enter a problem first.")18    else:19        with st.spinner("Thinking..."):20            try:21                response = openai.ChatCompletion.create(22                    model="gpt-3.5-turbo",23                    messages=[24                        {"role": "system", "content": "You are a helpful assistant that provides the best solutions to problems."},25                        {"role": "user", "content": problem}26                    ]27                )28                solution = response['choices'][0]['message']['content']29                st.success("Here's a suggested solution:")30                st.write(solution)31            except Exception as e:32                st.error(f"An error occurred: {e}")