AkashMnd commited on
Commit
a9442f2
·
1 Parent(s): 483397f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -8
app.py CHANGED
@@ -1,17 +1,49 @@
1
  import base64
2
  import gradio as gr
3
  import requests
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def encode_image(image_file):
6
  with open(image_file.name, "rb") as img_file:
7
  return base64.b64encode(img_file.read()).decode('utf-8')
8
 
9
- def send_to_openai(api_key, image_file):
10
  base64_image = encode_image(image_file)
11
 
12
  headers = {
13
  "Content-Type": "application/json",
14
- "Authorization": f"Bearer {api_key}"
15
  }
16
 
17
  payload = {
@@ -86,20 +118,24 @@ def send_to_openai(api_key, image_file):
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
  result_string = ' '.join(words + recognition)
95
- return result_string
96
-
 
 
 
 
97
 
98
  iface = gr.Interface(
99
  fn=send_to_openai,
100
- inputs=["text", "file"],
101
  outputs=["text"],
102
- title="Rice Leaf Disease Detection Demo Using GPT-4V(ision)",
103
- description="Made By Akash Mondal - https://github.com/akash-mondal GPT-4Vision Paper - https://cdn.openai.com/papers/GPTV_System_Card.pdf "
104
  )
105
  iface.launch(debug=True)
 
1
  import base64
2
  import gradio as gr
3
  import requests
4
+ import google.generativeai as palm
5
+ import json
6
+
7
+ oapi_key= os.getenv("openaiapi")
8
+ palm.configure(api_key=os.getenv("palmapi"))
9
+ model = 'models/text-bison-001'
10
+ temperature = 0.5
11
+ candidate_count = 1
12
+ top_k = 40
13
+ top_p = 0.95
14
+ max_output_tokens = 1024
15
+ text_b64 = 'WW91IGFyZSBhIFJpY2UgUGFkZHkgQWdyaWN1bHR1cmFsIFNjaWVudGlzdCAsIFlvdSB3aWxsIGJlIGdpdmVuIHRoZSBzd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BUk1fQ0FURUdPUllfVE9YSUNJVFkiLCJ0aHJlc2hvbGQiOiJCTE9DS19MT1dfQU5EX0FCT1ZFIn0seyJjYXRlZ29yeSI6IkhBUk1fQ0FURUdPUllfVklPTEVOQ0UiLCJ0aHJlc2hvbGQiOiJCTE9DS19NRURJVU1fQU5EX0FCT1ZFIn0seyJjYXRlZ29yeSI6IkhBUk1fQ0FURUdPUllfU0VYVUFMIiwidGhyZXNob2xkIjoiQkxPQ0tfTUVESVVNX0FORF9BQk9WRSJ9LHsiY2F0ZWdvcnkiOiJIQVJNX0NBVEVHT1JZX01FRElDQUwiLCJ0aHJlc2hvbGQiOiJCTE9DS19NRURJVU1fQU5EX0FCT1ZFIn0seyJjYXRlZ29yeSI6IkhBUk1fQ0FURUdPUllfREFOR0VST1VTIiwidGhyZXNob2xkIjoiQkxPQ0tfTUVESVVNX0FORF9BQk9WRSJ9XQ==' # @param {isTemplate: true}
18
+
19
+ # Convert the prompt text param from a bae64 string to a string.
20
+ text = base64.b64decode(text_b64).decode("utf-8")
21
+
22
+ # Convert the stop_sequences and safety_settings params from base64 strings to lists.
23
+ stop_sequences = json.loads(base64.b64decode(stop_sequences_b64).decode("utf-8"))
24
+ safety_settings = json.loads(base64.b64decode(safety_settings_b64).decode("utf-8"))
25
+
26
+ defaults = {
27
+ 'model': model,
28
+ 'temperature': temperature,
29
+ 'candidate_count': candidate_count,
30
+ 'top_k': top_k,
31
+ 'top_p': top_p,
32
+ 'max_output_tokens': max_output_tokens,
33
+ 'stop_sequences': stop_sequences,
34
+ 'safety_settings': safety_settings,
35
+ }
36
 
37
  def encode_image(image_file):
38
  with open(image_file.name, "rb") as img_file:
39
  return base64.b64encode(img_file.read()).decode('utf-8')
40
 
41
+ def send_to_openai(image_file):
42
  base64_image = encode_image(image_file)
43
 
44
  headers = {
45
  "Content-Type": "application/json",
46
+ "Authorization": f"Bearer {oapi_key}"
47
  }
48
 
49
  payload = {
 
118
  ],
119
  "max_tokens": 300
120
  }
121
+
122
 
123
  response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
124
  assistant_response = response.json()['choices'][0]['message']['content']
125
  recognition = assistant_response.split('\n')
126
  result_string = ' '.join(words + recognition)
127
+ response = palm.generate_text(
128
+ **defaults,
129
+ prompt=text + result_string
130
+ )
131
+ output_text = response.candidates[0]['output']
132
+ return output_text[8:]
133
 
134
  iface = gr.Interface(
135
  fn=send_to_openai,
136
+ inputs=["file"],
137
  outputs=["text"],
138
+ title="Rice Leaf Disease Detection Demo Using GPT-4V(ision) + PaLM 2",
139
+ description="Made By Akash Mondal - https://github.com/akash-mondal | GPT-4Vision Paper - https://cdn.openai.com/papers/GPTV_System_Card.pdf | PaLM2 Paper - https://arxiv.org/pdf/2305.10403.pdf "
140
  )
141
  iface.launch(debug=True)