Spaces:
Sleeping
Sleeping
import streamlit as st | |
import openai | |
# Initialize the OpenAI API | |
openai.api_key = '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' # Remember never to expose API keys in code | |
KNOWN_MODELS = [ | |
"Neural Networks", "Decision Trees", "Support Vector Machines", | |
"Random Forests", "Linear Regression", "Reinforcement Learning" | |
] | |
def recommend_ai_model_via_gpt(description): | |
messages = [ | |
{"role": "user", "content": f"Given the application described as: '{description}', which AI model would be most suitable?"} | |
] | |
try: | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", | |
messages=messages | |
) | |
recommendation = response['choices'][0]['message']['content'].strip() | |
return recommendation | |
except openai.error.OpenAIError as e: | |
return f"Error: {e}" | |
def explain_recommendation(model_name): | |
messages = [ | |
{"role": "user", "content": f"Why would {model_name} be a suitable choice for the application?"} | |
] | |
try: | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", | |
messages=messages | |
) | |
explanation = response['choices'][0]['message']['content'].strip() | |
return explanation | |
except openai.error.OpenAIError as e: | |
return f"Error: {e}" | |
# 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.") | |