Spaces:
Runtime error
Runtime error
serhii-korobchenko
commited on
Commit
•
0fecf04
1
Parent(s):
c1a178d
Update app.py
Browse files
app.py
CHANGED
@@ -30,13 +30,12 @@ def download_model_NLP():
|
|
30 |
sequence_length=128,)
|
31 |
model = keras_nlp.models.GPT2CausalLM.from_preset(
|
32 |
"gpt2_base_en", preprocessor=preprocessor)
|
33 |
-
return model
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
40 |
|
41 |
|
42 |
|
@@ -86,20 +85,23 @@ def predict_class(image):
|
|
86 |
def classify_image(image):
|
87 |
results = predict_class(image)
|
88 |
output = {labels.get(i): float(results[i]) for i in range(len(results))}
|
89 |
-
|
|
|
90 |
|
91 |
|
92 |
inputs = gr.inputs.Image(type="pil", label="Upload an image")
|
93 |
# outputs = gr.outputs.HTML() #uncomment for single class output
|
94 |
-
|
95 |
|
96 |
title = "<h1 style='text-align: center;'>Image Classifier</h1>"
|
97 |
description = "Upload an image and get the predicted class."
|
98 |
# css_code='body{background-image:url("file=wave.mp4");}'
|
99 |
|
|
|
|
|
100 |
gr.Interface(fn=classify_image,
|
101 |
inputs=inputs,
|
102 |
-
outputs=
|
103 |
title=title,
|
104 |
examples=[["00_plane.jpg"], ["01_car.jpg"], ["02_bird.jpg"], ["03_cat.jpg"], ["04_deer.jpg"]],
|
105 |
# css=css_code,
|
|
|
30 |
sequence_length=128,)
|
31 |
model = keras_nlp.models.GPT2CausalLM.from_preset(
|
32 |
"gpt2_base_en", preprocessor=preprocessor)
|
|
|
|
|
33 |
|
34 |
+
output = "total.h5"
|
35 |
+
id = "1-KgcnP1ayWQ6l2-4h723JCYPoWxzOnU3"
|
36 |
+
gdown.download(id=id, output=output, quiet=False)
|
37 |
+
model.load_weights(output)
|
38 |
+
return model
|
39 |
|
40 |
|
41 |
|
|
|
85 |
def classify_image(image):
|
86 |
results = predict_class(image)
|
87 |
output = {labels.get(i): float(results[i]) for i in range(len(results))}
|
88 |
+
result_NLP = model.generate("Deer is able to", max_length=100)
|
89 |
+
return output, result_NLP
|
90 |
|
91 |
|
92 |
inputs = gr.inputs.Image(type="pil", label="Upload an image")
|
93 |
# outputs = gr.outputs.HTML() #uncomment for single class output
|
94 |
+
output_1 = gr.outputs.Label(num_top_classes=4)
|
95 |
|
96 |
title = "<h1 style='text-align: center;'>Image Classifier</h1>"
|
97 |
description = "Upload an image and get the predicted class."
|
98 |
# css_code='body{background-image:url("file=wave.mp4");}'
|
99 |
|
100 |
+
model_NLP = download_model_NLP()
|
101 |
+
|
102 |
gr.Interface(fn=classify_image,
|
103 |
inputs=inputs,
|
104 |
+
outputs=[output_1, "text"],
|
105 |
title=title,
|
106 |
examples=[["00_plane.jpg"], ["01_car.jpg"], ["02_bird.jpg"], ["03_cat.jpg"], ["04_deer.jpg"]],
|
107 |
# css=css_code,
|