Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import openai | |
| import os | |
| # Securely fetch the OpenAI API key | |
| #try: | |
| openai.api_key = ('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') | |
| #except openai.APIError as e: | |
| # Log the error for debugging purposes | |
| #st.error("An error occurred while communicating with the OpenAI API.") | |
| # Optionally, log more detailed information for debugging | |
| #print("Error details:", e) | |
| # You might also want to implement additional logic here, like retrying the request, | |
| # sending a notification to an administrator, or providing a default response. | |
| KNOWN_MODELS = [ | |
| # General ML models | |
| "Neural Networks", "Decision Trees", "Support Vector Machines", | |
| "Random Forests", "Linear Regression", "Reinforcement Learning", | |
| "Logistic Regression", "k-Nearest Neighbors", "Naive Bayes", | |
| "Gradient Boosting Machines", "Regularization Techniques", | |
| "Ensemble Methods", "Time Series Analysis", | |
| # Deep Learning models | |
| "Deep Learning", "Convolutional Neural Networks", | |
| "Recurrent Neural Networks", "Transformer Models", | |
| "Generative Adversarial Networks", "Autoencoders", | |
| "Bidirectional LSTM", "Residual Networks (ResNets)", | |
| "Variational Autoencoders", | |
| # Computer Vision models and techniques | |
| "Object Detection (e.g., YOLO, SSD)", "Semantic Segmentation", | |
| "Image Classification", "Face Recognition", "Optical Character Recognition (OCR)", | |
| "Pose Estimation", "Style Transfer", "Image-to-Image Translation", | |
| "Image Generation", "Capsule Networks", | |
| # NLP models and techniques | |
| "BERT", "GPT", "ELMo", "T5", "Word2Vec", "Doc2Vec", | |
| "Topic Modeling", "Sentiment Analysis", "Text Classification", | |
| "Machine Translation", "Speech Recognition", "Sequence-to-Sequence Models", | |
| "Attention Mechanisms", "Named Entity Recognition", "Text Summarization" | |
| ] | |
| def recommend_ai_model_via_gpt(description, dataset_description): | |
| combined_description = f"{description} Dataset: {dataset_description}" | |
| messages = [{"role": "user", "content": combined_description}] | |
| response = openai.ChatCompletion.create(model="gpt-4", messages=messages) | |
| return response['choices'][0]['message']['content'].strip() | |
| def explain_recommendation(model_name): | |
| messages = [{"role": "user", "content": f"Why would {model_name} be a suitable choice for the application?"}] | |
| response = openai.ChatCompletion.create(model="gpt-4", messages=messages) | |
| return response['choices'][0]['message']['content'].strip() | |
| # Streamlit UI | |
| if 'show_dataset_description' not in st.session_state: | |
| st.session_state.show_dataset_description = False | |
| st.image("./A8title.png") | |
| st.title('Discover the best model for your GenAI App') | |
| # Inserting blank space | |
| st.write("") | |
| st.write("") | |
| st.write("") | |
| st.markdown("<h4 style='font-size:20px;'>Outline below your app's functionality:</h4>", unsafe_allow_html=True) | |
| description = st.text_area("", key="app_description") | |
| if description: | |
| if st.button("Next", key="next_to_dataset"): | |
| st.session_state.show_dataset_description = True | |
| if 'show_dataset_description' in st.session_state and st.session_state.show_dataset_description: | |
| st.write("") | |
| st.write("") | |
| st.write("") | |
| st.markdown("<h4 style='font-size:20px;'>Detail your dataset for fine-tuning this model:</h4>", unsafe_allow_html=True) | |
| dataset_description = st.text_area("", key="dataset_description") | |
| if dataset_description: | |
| if st.button("Recommend AI Model", key="recommend_model_button"): | |
| recommended_model = recommend_ai_model_via_gpt(description, dataset_description) | |
| st.subheader(f"Recommended: {recommended_model}") | |
| explanation = explain_recommendation(recommended_model) | |
| st.write("Reason:", explanation) | |
| 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", key="submit_feedback_key"): | |
| st.session_state.feedback_submitted = True | |
| if st.session_state.feedback_submitted: | |
| st.success("Thank you for your feedback!") | |
| else: | |
| st.warning("Please provide a description of your application.") |