Spaces:
Sleeping
Sleeping
File size: 2,719 Bytes
bbbf02c 8d7d639 252ec19 25cc5a2 252ec19 25cc5a2 252ec19 |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
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.")
|