|
import gradio as gr |
|
import tensorflow as tf |
|
import numpy as np |
|
from tensorflow.keras.preprocessing import image |
|
from PIL import Image |
|
import os |
|
|
|
|
|
model = tf.keras.models.load_model("my_keras_model.h5") |
|
|
|
|
|
image_size = (224, 224) |
|
|
|
|
|
def predict_image(img): |
|
img = img.resize(image_size) |
|
img_array = image.img_to_array(img) |
|
img_array = np.expand_dims(img_array, axis=0) / 255.0 |
|
prediction = model.predict(img_array) |
|
|
|
|
|
class_names = ['Fractured', 'Normal'] |
|
predicted_class = class_names[int(prediction[0] > 0.5)] |
|
|
|
return f"Prediction: {predicted_class} (Confidence: {prediction[0][0]:.2f})" |
|
|
|
|
|
sample_images_dir = "samples" |
|
sample_images = [os.path.join(sample_images_dir, f) for f in os.listdir(sample_images_dir) if f.endswith(('.jpg', '.png'))] |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict_image, |
|
inputs=gr.Image(type="pil"), |
|
outputs=gr.Textbox(), |
|
examples=sample_images, |
|
title="Bone Fracture Detection", |
|
description="Upload an X-ray image or select a sample image to check for fractures.", |
|
article=""" |
|
## Instructions |
|
- Type a question or statement |
|
- Upload images or audio files |
|
- You can combine text with media files |
|
- Support 2 modalities at the same time |
|
- The model can analyze images and transcribe audio |
|
- For best results with images, use JPG or PNG files |
|
- For audio, use WAV, MP3, or FLAC files |
|
|
|
## Capabilities |
|
This chatbot can: |
|
- Answer questions and provide explanations |
|
- Describe and analyze images |
|
- Transcribe, translate, summarize, and analyze audio content |
|
- Process multiple inputs in the same message |
|
- Maintain context throughout the conversation |
|
""" |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
interface.launch() |