DSatishchandra commited on
Commit
4c89a16
·
verified ·
1 Parent(s): 74bcee8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -22
app.py CHANGED
@@ -1,27 +1,32 @@
 
 
 
 
1
  import gradio as gr
2
- import pandas as pd
3
 
4
- # Load the dataset from the uploaded CSV file
5
- df = pd.read_csv("thyroid_disease_data.csv")
 
6
 
7
- # Define the function to classify the text
8
- def classify_thyroid_disease(text):
9
- # Search the dataset for a matching symptom text (basic string matching)
10
- result = df[df['text'].str.contains(text, case=False, na=False)]
11
-
12
- # Return a diagnosis based on the found label
13
- if not result.empty:
14
- label = result['label'].iloc[0]
15
- diagnosis = "Hypothyroidism" if label == 0 else "Hyperthyroidism"
16
- return diagnosis
17
- return "No matching diagnosis found."
 
18
 
19
- # Create the Gradio interface
20
- interface = gr.Interface(
21
- fn=classify_thyroid_disease,
22
- inputs="text", # User input will be a text field
23
- outputs="text" # Output will be a text diagnosis
24
- )
25
 
26
- # Launch the Gradio app
27
- interface.launch()
 
1
+ import torch
2
+ from torchvision import models, transforms
3
+ from torch import nn, optim
4
+ from PIL import Image
5
  import gradio as gr
 
6
 
7
+ # Load a pre-trained model (e.g., ResNet50)
8
+ model = models.resnet50(pretrained=True)
9
+ model.fc = nn.Linear(model.fc.in_features, 2) # For binary classification (Thyroid: Positive/Negative)
10
 
11
+ # Define image transformation
12
+ transform = transforms.Compose([
13
+ transforms.Resize((224, 224)),
14
+ transforms.ToTensor(),
15
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
16
+ ])
17
+
18
+ # Example function to classify images
19
+ def classify_thyroid_image(image):
20
+ image = Image.open(image).convert("RGB")
21
+ image = transform(image).unsqueeze(0) # Add batch dimension
22
+ model.eval() # Set the model to evaluation mode
23
 
24
+ with torch.no_grad():
25
+ output = model(image)
26
+ _, predicted = torch.max(output, 1)
27
+
28
+ diagnosis = "Thyroid Disease Detected" if predicted.item() == 1 else "No Thyroid Disease"
29
+ return diagnosis
30
 
31
+ # Create a Gradio interface for image upload and camera input
32
+ gr.Interface(fn=classify_thyroid_image, inputs="image", outputs="text").launch()