MartinKosela commited on
Commit
d8ba00f
·
1 Parent(s): 779925b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -39
app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import openai
3
 
4
  # Initialize the OpenAI API
5
- openai.api_key = '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'
6
 
7
  KNOWN_MODELS = [
8
  "Neural Networks", "Decision Trees", "Support Vector Machines",
@@ -10,48 +10,34 @@ KNOWN_MODELS = [
10
  ]
11
 
12
  def recommend_ai_model_via_gpt(description):
13
- # Formulate a prompt for the large language model
14
- prompt = f"Given the application described as: '{description}', which AI model would be most suitable?"
 
15
 
16
- response = openai.ChatCompletion.create(
17
- model="gpt-3.5-turbo",
18
- prompt=prompt,
19
- max_tokens=50
20
- )
21
-
22
- recommendation = response.choices[0].text.strip()
23
- return recommendation
 
24
 
25
  def explain_recommendation(model_name):
26
- # Formulate a prompt for explanation
27
- prompt = f"Why would {model_name} be a suitable choice for the application?"
28
-
29
- response = openai.ChatCompletion.create(
30
- model="gpt-3.5-turbo",
31
- prompt=prompt,
32
- max_tokens=150
33
- )
34
 
35
- explanation = response.choices[0].text.strip()
36
- return explanation
37
-
38
- def get_feedback():
39
- feedback = input("Was this recommendation helpful? (yes/no): ").lower()
40
- if feedback == 'yes':
41
- print("Thank you for your feedback!")
42
- else:
43
- print("Thank you! We'll strive to improve.")
44
-
45
- def rate_explanation():
46
  try:
47
- rating = int(input("Rate the explanation from 1 (worst) to 5 (best): "))
48
- if 1 <= rating <= 5:
49
- print("Thank you for rating!")
50
- else:
51
- print("Invalid rating. Please rate between 1 and 5.")
52
- except ValueError:
53
- print("Invalid input. Please enter a number between 1 and 5.")
54
-
55
 
56
  # Streamlit UI
57
  st.title('AI Model Recommender')
@@ -77,4 +63,3 @@ if st.button("Recommend AI Model"):
77
  st.success("Thank you for your feedback!")
78
  else:
79
  st.warning("Please provide a description.")
80
-
 
2
  import openai
3
 
4
  # Initialize the OpenAI API
5
+ openai.api_key = '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' # Remember never to expose API keys in code
6
 
7
  KNOWN_MODELS = [
8
  "Neural Networks", "Decision Trees", "Support Vector Machines",
 
10
  ]
11
 
12
  def recommend_ai_model_via_gpt(description):
13
+ messages = [
14
+ {"role": "user", "content": f"Given the application described as: '{description}', which AI model would be most suitable?"}
15
+ ]
16
 
17
+ try:
18
+ response = openai.ChatCompletion.create(
19
+ model="gpt-3.5-turbo",
20
+ messages=messages
21
+ )
22
+ recommendation = response['choices'][0]['message']['content'].strip()
23
+ return recommendation
24
+ except openai.error.OpenAIError as e:
25
+ return f"Error: {e}"
26
 
27
  def explain_recommendation(model_name):
28
+ messages = [
29
+ {"role": "user", "content": f"Why would {model_name} be a suitable choice for the application?"}
30
+ ]
 
 
 
 
 
31
 
 
 
 
 
 
 
 
 
 
 
 
32
  try:
33
+ response = openai.ChatCompletion.create(
34
+ model="gpt-3.5-turbo",
35
+ messages=messages
36
+ )
37
+ explanation = response['choices'][0]['message']['content'].strip()
38
+ return explanation
39
+ except openai.error.OpenAIError as e:
40
+ return f"Error: {e}"
41
 
42
  # Streamlit UI
43
  st.title('AI Model Recommender')
 
63
  st.success("Thank you for your feedback!")
64
  else:
65
  st.warning("Please provide a description.")