devdata commited on
Commit
fc6b019
·
1 Parent(s): d6df4f6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -24
app.py CHANGED
@@ -5,7 +5,6 @@ import os
5
 
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
8
- # Load the model
9
  learn = load_learner('model.pkl')
10
 
11
  # Define the labels
@@ -13,38 +12,38 @@ labels = learn.dls.vocab
13
 
14
  # Define a function for generating text
15
  def generate_text(prompt):
16
- response = openai.Completion.create(
17
- engine="davinci",
18
- prompt=prompt,
19
- max_tokens=1024,
20
- n=1,
21
- stop=None,
22
- temperature=0.7,
23
- )
24
- return response.choices[0].text.strip()
25
 
26
  # Define a function to handle user queries
27
  def handle_query(query, chat_history):
28
- response = openai.ChatCompletion.create(
29
- model="gpt-3.5-turbo",
30
- messages=[{"role": "system", "content": "You are a helpful assistant you kow about plant Disease."},
31
- {"role": "user", "content": query}] + chat_history
32
- )
33
- return response.choices[0].message['content']
34
 
35
  # Define the prediction function
36
  def predict(img):
37
- img = PILImage.create(img)
38
- pred,pred_idx,probs = learn.predict(img)
39
- prediction = {labels[i]: float(probs[i]) for i in range(len(labels))}
40
- chat_prompt = f"The model predicted {prediction}."
41
- chat_response = generate_text(chat_prompt)
42
- return {**prediction, 'chat_response': chat_response}
43
 
44
  # Define the chat function
45
  def chat(query, chat_history):
46
- chat_response = handle_query(query, chat_history)
47
- return chat_response
48
 
49
  # Define the examples
50
  examples = ['image.jpg']
 
5
 
6
  openai.api_key = os.getenv("OPENAI_API_KEY")
7
 
 
8
  learn = load_learner('model.pkl')
9
 
10
  # Define the labels
 
12
 
13
  # Define a function for generating text
14
  def generate_text(prompt):
15
+ response = openai.Completion.create(
16
+ engine="davinci",
17
+ prompt=prompt,
18
+ max_tokens=1024,
19
+ n=1,
20
+ stop=None,
21
+ temperature=0.7,
22
+ )
23
+ return response.choices[0].text.strip()
24
 
25
  # Define a function to handle user queries
26
  def handle_query(query, chat_history):
27
+ response = openai.ChatCompletion.create(
28
+ model="gpt-3.5-turbo",
29
+ messages=[{"role": "system", "content": "You are a helpful assistant."},
30
+ {"role": "user", "content": query}] + chat_history
31
+ )
32
+ return response.choices[0].message['content']
33
 
34
  # Define the prediction function
35
  def predict(img):
36
+ img = PILImage.create(img)
37
+ pred,pred_idx,probs = learn.predict(img)
38
+ prediction = {labels[i]: float(probs[i]) for i in range(len(labels))}
39
+ chat_prompt = f"The model predicted {prediction}."
40
+ chat_response = generate_text(chat_prompt)
41
+ return {**prediction, 'chat_response': chat_response}
42
 
43
  # Define the chat function
44
  def chat(query, chat_history):
45
+ chat_response = handle_query(query, chat_history)
46
+ return chat_response
47
 
48
  # Define the examples
49
  examples = ['image.jpg']