Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import numpy as np
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
def classify_fish(image):
|
| 6 |
+
return {"Baby": 0.1, "Small": 0.2, "Medium": 0.5, "Large": 0.2}
|
| 7 |
+
|
| 8 |
+
def emit_sound(frequency: int):
|
| 9 |
+
return f"Emitting sound at {frequency} Hz"
|
| 10 |
+
|
| 11 |
+
def fish_classification_ui(image):
|
| 12 |
+
result = classify_fish(image)
|
| 13 |
+
return result
|
| 14 |
+
|
| 15 |
+
def sound_control_ui(frequency):
|
| 16 |
+
return emit_sound(frequency)
|
| 17 |
+
|
| 18 |
+
def chat_bot(message):
|
| 19 |
+
message = message.lower()
|
| 20 |
+
qa_pairs = {
|
| 21 |
+
"status": "π§ AI Agent is running fine. Monitoring in progress.",
|
| 22 |
+
"fish": "π We detect Baby, Small, Medium, and Large fish. Currently focusing on high-value species.",
|
| 23 |
+
"sound": "π Emitting pulsed low-frequency sound to attract fish safely.",
|
| 24 |
+
"species": "π High-demand species detected include Rohu, Katla, Murrel.",
|
| 25 |
+
"how many": "π Estimated fish count: Baby - 20, Small - 15, Medium - 10, Large - 5.",
|
| 26 |
+
"quality": "β
Fish health and activity levels look optimal.",
|
| 27 |
+
"ocr": "π OCR scanning dam gate status and water markings.",
|
| 28 |
+
"ner": "π§ NER detects and classifies fish species from scientific names in camera labels.",
|
| 29 |
+
"camera": "π₯ Camera feed processed via CNN for size and movement analysis.",
|
| 30 |
+
"size": "π Fish size is auto-categorized as Baby, Small, Medium, or Large using our model.",
|
| 31 |
+
"dead fish": "β οΈ No dead fish detected near the thrust gates currently.",
|
| 32 |
+
"thrust gate": "πͺ Monitoring open/close cycle and alerting when fish are near during thrust events.",
|
| 33 |
+
"maintenance": "π οΈ Regular AI system checks scheduled weekly.",
|
| 34 |
+
"data": "π Sensor data streamed every 2 seconds from riverbanks and gates.",
|
| 35 |
+
"alert": "π¨ Auto-alerts sent to fishermen if high movement or danger is detected.",
|
| 36 |
+
"chat": "π¬ I can assist engineers and fishermen with system status, fish count, and more.",
|
| 37 |
+
"retrain": "π§βπ» Retraining is supported manually with new images via UI.",
|
| 38 |
+
"dashboard": "π The live dashboard shows fish count, sound activity, and gate logs.",
|
| 39 |
+
"developer": "π¨βπ» Developed by EchoFishAI with Gradio, CNN, and RL techniques.",
|
| 40 |
+
"help": "π You can ask about fish, gate status, sound, camera, or system alerts."
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
for key in qa_pairs:
|
| 44 |
+
if key in message:
|
| 45 |
+
return qa_pairs[key]
|
| 46 |
+
return "π€ Hello! Ask me about fish, sound, species, status, gates, or AI system help."
|
| 47 |
+
|
| 48 |
+
with gr.Blocks() as demo:
|
| 49 |
+
gr.Markdown("# EchoFishAI π")
|
| 50 |
+
gr.Markdown("Smart Fish Tracking & Attraction System with AI")
|
| 51 |
+
|
| 52 |
+
with gr.Tab("Fish Classifier"):
|
| 53 |
+
with gr.Row():
|
| 54 |
+
image_input = gr.Image(type="pil")
|
| 55 |
+
output = gr.Label()
|
| 56 |
+
classify_btn = gr.Button("Classify Fish")
|
| 57 |
+
classify_btn.click(fish_classification_ui, inputs=image_input, outputs=output)
|
| 58 |
+
|
| 59 |
+
with gr.Tab("Sound Emission"):
|
| 60 |
+
with gr.Row():
|
| 61 |
+
freq_input = gr.Slider(minimum=10, maximum=1000, step=10, label="Frequency (Hz)")
|
| 62 |
+
sound_output = gr.Textbox()
|
| 63 |
+
emit_btn = gr.Button("Emit Sound")
|
| 64 |
+
emit_btn.click(sound_control_ui, inputs=freq_input, outputs=sound_output)
|
| 65 |
+
|
| 66 |
+
with gr.Tab("Ask AI Agent"):
|
| 67 |
+
with gr.Row():
|
| 68 |
+
chatbot_input = gr.Textbox(label="Ask something...")
|
| 69 |
+
chatbot_output = gr.Textbox(label="Response")
|
| 70 |
+
chat_btn = gr.Button("Send")
|
| 71 |
+
chat_btn.click(chat_bot, inputs=chatbot_input, outputs=chatbot_output)
|
| 72 |
+
|
| 73 |
+
if __name__ == "__main__":
|
| 74 |
+
demo.launch(debug=True)
|