Spaces:
Sleeping
Sleeping
Commit
·
9a7103b
1
Parent(s):
05f9deb
wew
Browse files- app.py +11 -44
- requirements.txt +2 -5
app.py
CHANGED
@@ -1,49 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
3 |
-
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, confusion_matrix, roc_curve, auc
|
4 |
-
import matplotlib.pyplot as plt
|
5 |
-
import numpy as np
|
6 |
|
7 |
-
|
8 |
-
|
|
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
def calculate_metrics(y_true, y_pred):
|
16 |
-
accuracy = accuracy_score(y_true, y_pred)
|
17 |
-
precision, recall, f1, _ = precision_recall_fscore_support(y_true, y_pred, average='binary')
|
18 |
-
cm = confusion_matrix(y_true, y_pred)
|
19 |
-
fpr, tpr, _ = roc_curve(y_true, y_pred)
|
20 |
-
roc_auc = auc(fpr, tpr)
|
21 |
-
return accuracy, precision, recall, f1, cm, fpr, tpr, roc_auc
|
22 |
|
23 |
-
|
24 |
-
# Plot confusion matrix here
|
25 |
-
pass
|
26 |
-
|
27 |
-
def plot_roc_curve(fpr, tpr, roc_auc):
|
28 |
-
# Plot ROC curve here
|
29 |
-
pass
|
30 |
-
|
31 |
-
# Replace this with actual test data and predictions
|
32 |
-
y_true = [0, 1, 0, 1] # True labels
|
33 |
-
y_pred = [0, 1, 0, 1] # Predicted labels
|
34 |
-
|
35 |
-
# Calculate metrics
|
36 |
-
accuracy, precision, recall, f1, cm, fpr, tpr, roc_auc = calculate_metrics(y_true, y_pred)
|
37 |
-
|
38 |
-
# Plot confusion matrix and ROC curve
|
39 |
-
plot_confusion_matrix(cm)
|
40 |
-
plot_roc_curve(fpr, tpr, roc_auc)
|
41 |
-
|
42 |
-
# Create a Gradio interface
|
43 |
-
interface = gr.Interface(
|
44 |
-
fn=analyze_sentiment,
|
45 |
-
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter Text Here..."),
|
46 |
-
outputs="text"
|
47 |
-
)
|
48 |
-
|
49 |
-
interface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from PIL import Image
|
|
|
|
|
|
|
3 |
|
4 |
+
def to_black_and_white(input_image):
|
5 |
+
bw_image = input_image.convert("L") # Convert to grayscale
|
6 |
+
return bw_image
|
7 |
|
8 |
+
with gr.Blocks() as app:
|
9 |
+
gr.Markdown("### Black and White Image Maker")
|
10 |
+
with gr.Row():
|
11 |
+
image_input = gr.Image(type="pil", label="Upload your Image")
|
12 |
+
image_output = gr.Image(type="pil", label="Black and White Image", tool="editor")
|
13 |
|
14 |
+
image_input.change(to_black_and_white, inputs=image_input, outputs=image_output)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
app.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
@@ -1,5 +1,2 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
scikit-learn
|
4 |
-
matplotlib
|
5 |
-
tensorflow
|
|
|
1 |
+
gradio
|
2 |
+
PIL
|
|
|
|
|
|