Update app.py
Browse files
app.py
CHANGED
|
@@ -24,7 +24,9 @@ import matplotlib.pyplot as plt
|
|
| 24 |
import numpy as np
|
| 25 |
from PIL import Image
|
| 26 |
from timm import create_model
|
| 27 |
-
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
safe_tensors = "model.safetensors" #hf_hub_download(repo_id="subhuatharva/swim-224-base-satellite-image-classification", filename="model.safetensors")
|
|
@@ -74,8 +76,13 @@ def model_output(image):
|
|
| 74 |
predictions = predictions.float().numpy().flatten()
|
| 75 |
pred_labels = one_hot_decoding(predictions)
|
| 76 |
output_text = " ".join(pred_labels)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
return
|
| 79 |
|
| 80 |
app = gr.Interface(fn=model_output, inputs="image", outputs="text", title=title,
|
| 81 |
description=description, examples=[["sample_images/train_142.jpg"], ["sample_images/train_75.jpg"],["sample_images/train_32.jpg"], ["sample_images/train_59.jpg"], ["sample_images/train_67.jpg"], ["sample_images/train_92.jpg"], ["sample_images/random_satellite_image.png"]])
|
|
|
|
| 24 |
import numpy as np
|
| 25 |
from PIL import Image
|
| 26 |
from timm import create_model
|
| 27 |
+
from langchain_fireworks import ChatFireworks
|
| 28 |
+
from langchain.schema import HumanMessage
|
| 29 |
+
import os
|
| 30 |
|
| 31 |
|
| 32 |
safe_tensors = "model.safetensors" #hf_hub_download(repo_id="subhuatharva/swim-224-base-satellite-image-classification", filename="model.safetensors")
|
|
|
|
| 76 |
predictions = predictions.float().numpy().flatten()
|
| 77 |
pred_labels = one_hot_decoding(predictions)
|
| 78 |
output_text = " ".join(pred_labels)
|
| 79 |
+
query = f"summarize the classified satellite image labels {output_text} and summarize if or how these factors can cause deforestation"
|
| 80 |
+
|
| 81 |
+
api_key = os.getenv("FIREWORKS_API_KEY")
|
| 82 |
+
llm = ChatFireworks(api_key=api_key, model="accounts/fireworks/models/mixtral-8x7b-instruct")
|
| 83 |
+
message = HumanMessage(query)
|
| 84 |
|
| 85 |
+
return llm([message]).content
|
| 86 |
|
| 87 |
app = gr.Interface(fn=model_output, inputs="image", outputs="text", title=title,
|
| 88 |
description=description, examples=[["sample_images/train_142.jpg"], ["sample_images/train_75.jpg"],["sample_images/train_32.jpg"], ["sample_images/train_59.jpg"], ["sample_images/train_67.jpg"], ["sample_images/train_92.jpg"], ["sample_images/random_satellite_image.png"]])
|