alexdekan030 commited on
Commit
0b08102
·
verified ·
1 Parent(s): 414980a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -4
app.py CHANGED
@@ -1,7 +1,45 @@
1
  import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline, AutoImageProcessor, AutoModelForImageClassification
3
+ import torch
4
 
5
+ # Initialize the model and processor
6
+ processor = AutoImageProcessor.from_pretrained("alexdekan030/autotrain-awcru-nr8j7")
7
+ model = AutoModelForImageClassification.from_pretrained("alexdekan030/autotrain-awcru-nr8j7")
8
+ pipe = pipeline("image-classification", model=model, image_processor=processor)
9
 
10
+ def predict_pneumonia(image):
11
+ """
12
+ Predict whether an image shows pneumonia or normal chest X-ray
13
+ Args:
14
+ image: Input image
15
+ Returns:
16
+ dict: Dictionary containing prediction probabilities
17
+ """
18
+ # Make prediction
19
+ result = pipe(image)
20
+
21
+ # Create a formatted output dictionary
22
+ probabilities = {pred['label']: float(pred['score']) for pred in result}
23
+
24
+ return probabilities
25
+
26
+ # Create the Gradio interface
27
+ demo = gr.Interface(
28
+ fn=predict_pneumonia,
29
+ inputs=gr.Image(type="pil"),
30
+ outputs=gr.Label(num_top_classes=2),
31
+ title="Pneumonia Detection from Chest X-rays",
32
+ description="""Upload a chest X-ray image to detect if it shows signs of pneumonia.
33
+ The model will classify the image as either 'NORMAL' or 'PNEUMONIA'
34
+ and provide confidence scores for each class.""",
35
+ examples=[
36
+ # You can add example images here if you have them
37
+ # ["path/to/example1.jpg"],
38
+ # ["path/to/example2.jpg"]
39
+ ],
40
+ theme=gr.themes.Base()
41
+ )
42
+
43
+ # Launch the app
44
+ if __name__ == "__main__":
45
+ demo.launch(share=True)