Spaces:
Sleeping
Sleeping
SarowarSaurav
commited on
Commit
•
30f242a
1
Parent(s):
75e60e4
Update app.py
Browse files
app.py
CHANGED
@@ -1,86 +1,54 @@
|
|
1 |
-
import pandas as pd
|
2 |
import gradio as gr
|
3 |
-
import
|
4 |
-
from
|
|
|
|
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
uid = hashlib.md5(email.encode()).hexdigest()
|
11 |
-
rev = datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') # Current timestamp for revision
|
12 |
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
EMAIL:{email}
|
22 |
-
UID:{uid}
|
23 |
-
REV:{rev}
|
24 |
-
END:VCARD"""
|
25 |
-
return vcf_template.format(
|
26 |
-
name=row['Name'],
|
27 |
-
function=row['Function'],
|
28 |
-
designation=row['Designation'],
|
29 |
-
number=row['Number'],
|
30 |
-
email=email,
|
31 |
-
uid=uid,
|
32 |
-
rev=rev
|
33 |
-
)
|
34 |
|
35 |
-
#
|
36 |
-
def
|
37 |
-
#
|
38 |
-
|
39 |
-
df['Number'] = df['Number'].astype(str) # Ensure phone numbers are strings
|
40 |
|
41 |
-
#
|
42 |
-
|
|
|
|
|
|
|
43 |
|
44 |
-
#
|
45 |
-
|
46 |
-
with open(vcf_file_name, 'w') as vcf_file:
|
47 |
-
vcf_file.write(vcf_data)
|
48 |
|
49 |
-
return
|
50 |
-
|
51 |
-
# Custom CSS and HTML
|
52 |
-
css = """
|
53 |
-
.gradio-container {
|
54 |
-
background: rgb(14, 43, 99);
|
55 |
-
display: flex;
|
56 |
-
flex-direction: column;
|
57 |
-
align-items: center;
|
58 |
-
color: #fff;
|
59 |
-
padding: 20px;
|
60 |
-
}
|
61 |
-
.gradio-input, .gradio-output {
|
62 |
-
background: rgb(28, 56, 113);
|
63 |
-
color: #fff;
|
64 |
-
}
|
65 |
-
footer {
|
66 |
-
display: none !important;
|
67 |
-
}
|
68 |
-
"""
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
<p style="text-align: center; color: #fff;">Upload an Excel file containing contact information in the following format: Name, Designation, Function, GRADE, Email, Number. The output will be a VCF file containing the contact information.</p>
|
75 |
"""
|
76 |
|
77 |
-
# Gradio
|
78 |
-
|
79 |
-
|
80 |
-
gr.
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
85 |
|
86 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
4 |
+
from PIL import Image
|
5 |
+
import requests
|
6 |
|
7 |
+
# Load a pre-trained Vision Transformer model from Hugging Face
|
8 |
+
model_name = "nateraw/vit-base-patch16-224-in21k" # Replace with the model you've trained or a similar model
|
9 |
+
model = ViTForImageClassification.from_pretrained(model_name)
|
10 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained(model_name)
|
|
|
|
|
11 |
|
12 |
+
# Define the disease labels (placeholders)
|
13 |
+
labels = {
|
14 |
+
0: "Healthy",
|
15 |
+
1: "Tobacco Mosaic Virus",
|
16 |
+
2: "Brown Spot",
|
17 |
+
3: "Frog Eye Leaf Spot",
|
18 |
+
4: "Other"
|
19 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
# Define a function for disease detection
|
22 |
+
def detect_disease(image):
|
23 |
+
# Preprocess the image
|
24 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
|
|
25 |
|
26 |
+
# Run the model
|
27 |
+
with torch.no_grad():
|
28 |
+
outputs = model(**inputs)
|
29 |
+
logits = outputs.logits
|
30 |
+
predicted_class = logits.argmax().item()
|
31 |
|
32 |
+
# Get disease name from label dictionary
|
33 |
+
disease_name = labels.get(predicted_class, "Unknown Disease")
|
|
|
|
|
34 |
|
35 |
+
return f"Disease Detected: {disease_name}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
|
37 |
+
# Build Gradio Interface
|
38 |
+
title = "Tobacco Leaf Disease Detection"
|
39 |
+
description = """
|
40 |
+
Upload or take a real-time picture of a tobacco leaf, and the app will detect the disease (if any).
|
|
|
41 |
"""
|
42 |
|
43 |
+
# Create Gradio interface with camera and real-time processing
|
44 |
+
iface = gr.Interface(
|
45 |
+
fn=detect_disease,
|
46 |
+
inputs=gr.Image(source="camera", type="pil", tool="editor"),
|
47 |
+
outputs="text",
|
48 |
+
title=title,
|
49 |
+
description=description,
|
50 |
+
live=True # Enables real-time processing
|
51 |
+
)
|
52 |
|
53 |
+
# Launch Gradio app
|
54 |
+
iface.launch()
|