Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,39 +1,12 @@
|
|
1 |
import base64
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
-
import google.generativeai as
|
5 |
import json
|
6 |
import os
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
model = 'models/text-bison-001'
|
11 |
-
temperature = 0.5
|
12 |
-
candidate_count = 1
|
13 |
-
top_k = 40
|
14 |
-
top_p = 0.95
|
15 |
-
max_output_tokens = 1024
|
16 |
-
text_b64 = 'WW91IGFyZSBhIFJpY2UgUGFkZHkgQWdyaWN1bHR1cmFsIFNjaWVudGlzdCAsIFlvdSB3aWxsIGJlIGdpdmVuIHRoZSBzdGF0ZSBvZiB0aGUgcGFkZHkoYSBwaWN0dXJlIGRlc2NyaXB0aW9uICkgYW5kIHlvdSB3aWxsIGhhdmUgdG8gYWR2aWNlIG9uIHRoZSBjb3JyZWN0IHJlbWVkeUlucHV0IC0gU2hlYXRoIFllcyBNZWFuaW5nIC0gIFRoZSBGYXJtZXIgaGFzIHNob3duIHlvdSBhIHBpY3R1cmUgb2YgU2hlYXRoIHBhcnQgb2YgdGhlIHBhZGR5IGFuZCBpdCBpcyBzdWZmZXJpbmcgZnJvbSBTaGVhdGggUm90ICwgYWR2aWNlIHRoZSBmYXJtZXIgb24gaG93IHRvIGZpeCB0aGlzSW5wdXQgLSBTaGVhdGggTm8gTWVhbmluZyAtIFRoZSBGYXJtZXIgaGFzIHNob3duIHlvdSBhIHBpY3R1cmUgb2YgU2hlYXRoIHBhcnQgb2YgdGhlIHBhZGR5IGFuZCBpdCBpcyBoZWFsdGh5ICxjb25ncmF0dWxhdGUgYW5kIGFkdmljZSBmYXJtZXIgb24gaG93IHRvIG1haW50YWluIGl0SW5wdXQgLSBMZWFmIFllcyBObyBObyBNZWFuaW5nIC0gVGhlIEZhcm1lciBoYXMgc2hvd24geW91IGEgcGljdHVyZSBvZiBMZWFmIHBhcnQgb2YgdGhlIHBhZGR5IGFuZ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V0OiBQbGVhc2UgcHJvdmlkZSBUaGUgYXBwIHdpdGggYW5vdGhlciBwaWN0dXJlIHRha2VuIGZyb20gcG9zc2libHkgYSBkaWZmZXJlbnQgYW5nbGUgb3Igd2l0aCBiZXR0ZXIgbGlnaHRpbmcgLCBvciB1c2UgYSBkaWZmZXJlbnQgc2FtcGxlIGxlYWYKaW5wdXQ6' # @param {isTemplate: true}
|
17 |
-
stop_sequences_b64 = 'W10='
|
18 |
-
safety_settings_b64 = 'W3siY2F0ZWdvcnkiOiJIQVJNX0NBVEVHT1JZX0RFUk9HQVRPUlkiLCJ0aHJlc2hvbGQiOiJCTE9DS19MT1dfQU5EX0FCT1ZFIn0seyJjYXRlZ29yeSI6IkhBUk1fQ0FURUdPUllfVE9YSUNJVFkiLCJ0aHJlc2hvbGQiOiJCTE9DS19MT1dfQU5EX0FCT1ZFIn0seyJjYXRlZ29yeSI6IkhBUk1fQ0FURUdPUllfVklPTEVOQ0UiLCJ0aHJlc2hvbGQiOiJCTE9DS19NRURJVU1fQU5EX0FCT1ZFIn0seyJjYXRlZ29yeSI6IkhBUk1fQ0FURUdPUllfU0VYVUFMIiwidGhyZXNob2xkIjoiQkxPQ0tfTUVESVVNX0FORF9BQk9WRSJ9LHsiY2F0ZWdvcnkiOiJIQVJNX0NBVEVHT1JZX01FRElDQUwiLCJ0aHJlc2hvbGQiOiJCTE9DS19NRURJVU1fQU5EX0FCT1ZFIn0seyJjYXRlZ29yeSI6IkhBUk1fQ0FURUdPUllfREFOR0VST1VTIiwidGhyZXNob2xkIjoiQkxPQ0tfTUVESVVNX0FORF9BQk9WRSJ9XQ==' # @param {isTemplate: true}
|
19 |
-
|
20 |
-
# Convert the prompt text param from a bae64 string to a string.
|
21 |
-
text = base64.b64decode(text_b64).decode("utf-8")
|
22 |
-
|
23 |
-
# Convert the stop_sequences and safety_settings params from base64 strings to lists.
|
24 |
-
stop_sequences = json.loads(base64.b64decode(stop_sequences_b64).decode("utf-8"))
|
25 |
-
safety_settings = json.loads(base64.b64decode(safety_settings_b64).decode("utf-8"))
|
26 |
-
|
27 |
-
defaults = {
|
28 |
-
'model': model,
|
29 |
-
'temperature': temperature,
|
30 |
-
'candidate_count': candidate_count,
|
31 |
-
'top_k': top_k,
|
32 |
-
'top_p': top_p,
|
33 |
-
'max_output_tokens': max_output_tokens,
|
34 |
-
'stop_sequences': stop_sequences,
|
35 |
-
'safety_settings': safety_settings,
|
36 |
-
}
|
37 |
|
38 |
def encode_image(image_file):
|
39 |
with open(image_file.name, "rb") as img_file:
|
@@ -125,18 +98,13 @@ def send_to_openai(image_file):
|
|
125 |
assistant_response = response.json()['choices'][0]['message']['content']
|
126 |
recognition = assistant_response.split('\n')
|
127 |
result_string = ' '.join(words + recognition)
|
128 |
-
|
129 |
-
**defaults,
|
130 |
-
prompt=text + result_string
|
131 |
-
)
|
132 |
-
output_text = response.candidates[0]['output']
|
133 |
-
return output_text[8:]
|
134 |
|
135 |
iface = gr.Interface(
|
136 |
fn=send_to_openai,
|
137 |
inputs=["file"],
|
138 |
outputs=["text"],
|
139 |
-
title="Rice Leaf Disease Detection Demo Using GPT-4V
|
140 |
-
description="Made By Akash Mondal - https://github.com/akash-mondal | GPT-4Vision Paper - https://cdn.openai.com/papers/GPTV_System_Card.pdf
|
141 |
)
|
142 |
iface.launch(debug=True)
|
|
|
1 |
import base64
|
2 |
import gradio as gr
|
3 |
import requests
|
4 |
+
import google.generativeai as genai
|
5 |
import json
|
6 |
import os
|
7 |
|
8 |
+
genai.configure(api_key=os.getenv("genai"))
|
9 |
+
oapi_key= os.getenv("openai")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
def encode_image(image_file):
|
12 |
with open(image_file.name, "rb") as img_file:
|
|
|
98 |
assistant_response = response.json()['choices'][0]['message']['content']
|
99 |
recognition = assistant_response.split('\n')
|
100 |
result_string = ' '.join(words + recognition)
|
101 |
+
return result_string
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
iface = gr.Interface(
|
104 |
fn=send_to_openai,
|
105 |
inputs=["file"],
|
106 |
outputs=["text"],
|
107 |
+
title="Rice Leaf Disease Detection Demo Using GPT-4V",
|
108 |
+
description="Made By Akash Mondal - https://github.com/akash-mondal | GPT-4Vision Paper - https://cdn.openai.com/papers/GPTV_System_Card.pdf "
|
109 |
)
|
110 |
iface.launch(debug=True)
|