kedimestan commited on
Commit
d501ffc
·
verified ·
1 Parent(s): 069eaa5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -1,5 +1,4 @@
1
- from fastapi import FastAPI, UploadFile, File, HTTPException
2
- from fastapi.responses import JSONResponse
3
  import torch
4
  import torch.nn as nn
5
  from torchvision import transforms
@@ -8,9 +7,6 @@ from PIL import Image
8
  import io
9
  from huggingface_hub import hf_hub_download
10
 
11
- # FastAPI uygulamasını başlat
12
- app = FastAPI()
13
-
14
  # Cihaz ayarı
15
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
16
 
@@ -81,21 +77,12 @@ def predict(image: Image.Image):
81
  prediction = "Positive" if output[0] > 0.5 else "Negative"
82
  return {"Prediction": prediction, "Probability": round(float(output[0]), 2)}
83
 
84
- # Ana API rotası
85
- @app.post("/predict")
86
- async def predict_image(file: UploadFile = File(...)):
87
- try:
88
- # Görüntüyü oku
89
- image_data = await file.read()
90
- image = Image.open(io.BytesIO(image_data)).convert("RGB")
91
-
92
- # Tahmin yap
93
- result = predict(image)
94
- return JSONResponse(content=result)
95
- except Exception as e:
96
- return JSONResponse(content={"error": str(e)}, status_code=400)
97
 
98
- # Ana sayfa
99
- @app.get("/")
100
- def home():
101
- return {"message": "Upload an image to /predict for classification."}
 
1
+ import gradio as gr
 
2
  import torch
3
  import torch.nn as nn
4
  from torchvision import transforms
 
7
  import io
8
  from huggingface_hub import hf_hub_download
9
 
 
 
 
10
  # Cihaz ayarı
11
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
12
 
 
77
  prediction = "Positive" if output[0] > 0.5 else "Negative"
78
  return {"Prediction": prediction, "Probability": round(float(output[0]), 2)}
79
 
80
+ # Gradio arayüzü
81
+ def gradio_interface(image):
82
+ return predict(image)
83
+
84
+ # Gradio arayüzü oluşturma
85
+ inputs = gr.Image(type="pil", label="Upload Image")
86
+ outputs = gr.JSON(label="Prediction Result")
 
 
 
 
 
 
87
 
88
+ gr.Interface(fn=gradio_interface, inputs=inputs, outputs=outputs, title="Retinoblastoma Detection", theme="default").launch(debug=True)