Select_Model / app.py
MartinKosela's picture
Update app.py
bbbf02c
raw
history blame
2.72 kB
pip install openai
import streamlit as st
import openai
# Initialize the OpenAI API
openai.api_key = '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'
KNOWN_MODELS = [
"Neural Networks", "Decision Trees", "Support Vector Machines",
"Random Forests", "Linear Regression", "Reinforcement Learning"
]
def recommend_ai_model_via_gpt(description):
# Formulate a prompt for the large language model
prompt = f"Given the application described as: '{description}', which AI model would be most suitable?"
response = openai.Completion.create(
model="gpt-4.0-turbo",
prompt=prompt,
max_tokens=50
)
recommendation = response.choices[0].text.strip()
return recommendation
def explain_recommendation(model_name):
# Formulate a prompt for explanation
prompt = f"Why would {model_name} be a suitable choice for the application?"
response = openai.Completion.create(
model="gpt-4.0-turbo",
prompt=prompt,
max_tokens=150
)
explanation = response.choices[0].text.strip()
return explanation
def get_feedback():
feedback = input("Was this recommendation helpful? (yes/no): ").lower()
if feedback == 'yes':
print("Thank you for your feedback!")
else:
print("Thank you! We'll strive to improve.")
def rate_explanation():
try:
rating = int(input("Rate the explanation from 1 (worst) to 5 (best): "))
if 1 <= rating <= 5:
print("Thank you for rating!")
else:
print("Invalid rating. Please rate between 1 and 5.")
except ValueError:
print("Invalid input. Please enter a number between 1 and 5.")
# Streamlit UI
st.title('AI Model Recommender')
description = st.text_area("Describe your application:", "")
if st.button("Recommend AI Model"):
if description:
recommended_model = recommend_ai_model_via_gpt(description)
# Validate recommended model
if recommended_model not in KNOWN_MODELS:
st.warning("The recommendation is ambiguous. Please refine your description or consult an expert.")
else:
st.subheader(f"Recommended AI Model: {recommended_model}")
explanation = explain_recommendation(recommended_model)
st.write("Reason:", explanation)
# Collecting rating and feedback through Streamlit
rating = st.slider("Rate the explanation from 1 (worst) to 5 (best):", 1, 5)
feedback = st.text_input("Any additional feedback?")
if st.button("Submit Feedback"):
st.success("Thank you for your feedback!")
else:
st.warning("Please provide a description.")