AkashMnd commited on
Commit
f6b3153
1 Parent(s): c77361d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -2
app.py CHANGED
@@ -40,8 +40,58 @@ def send_to_openai(api_key, image_file):
40
  # Extract words from the assistant's response
41
  assistant_response = response.json()['choices'][0]['message']['content']
42
  words = assistant_response.split('\n')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
- return ' '.join(words)
45
 
46
- iface = gr.Interface(send_to_openai, ["text", "file"], "text")
 
 
 
 
 
47
  iface.launch()
 
40
  # Extract words from the assistant's response
41
  assistant_response = response.json()['choices'][0]['message']['content']
42
  words = assistant_response.split('\n')
43
+ checkresponse_lower = words.lower()
44
+ if "leaf" in checkresponse_lower:
45
+ payload = {
46
+ "model": "gpt-4-vision-preview",
47
+ "messages": [
48
+ {
49
+ "role": "user",
50
+ "content": [
51
+ {
52
+ "type": "text",
53
+ "text": "Answer in three words only, does the image uploaded have a healthy rice leaf - Yes or No , does the image uploaded have a rice leaf with Major (not small) circular spots - Yes or No , does the image uploaded have a rice leaf have a major yellowish discoloration in some areas (ignore spots) - Yes or No , DO NOT RESPOND IN MORE THAN THREE WORDS "
54
+ },
55
+ {
56
+ "type": "image_url",
57
+ "image_url": {
58
+ "url": f"data:image/jpeg;base64,{base64_image}"
59
+ }
60
+ }
61
+ ]
62
+ }
63
+ ],
64
+ "max_tokens": 300
65
+ }
66
+
67
+ elif "sheath" in checkresponse_lower:
68
+ payload = {
69
+ "model": "gpt-4-vision-preview",
70
+ "messages": [
71
+ {
72
+ "role": "user",
73
+ "content": [
74
+ {
75
+ "type": "text",
76
+ "text": "ANSWER IN ONLY ONE WORD , does the sheath part of the paddy in the image have sheath rot "
77
+ },
78
+ {
79
+ "type": "image_url",
80
+ "image_url": {
81
+ "url": f"data:image/jpeg;base64,{base64_image}"
82
+ }
83
+ }
84
+ ]
85
+ }
86
+ ],
87
+ "max_tokens": 300
88
+ }
89
 
 
90
 
91
+ response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
92
+ assistant_response = response.json()['choices'][0]['message']['content']
93
+ recognition = assistant_response.split('\n')
94
+ return ' '.join(words), ' '.join(recognition)
95
+
96
+ iface = gr.Interface(send_to_openai, ["text", "file"], ["text", "text"])
97
  iface.launch()