Spaces:
Runtime error
Runtime error
Add application file
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from PIL import Image
|
4 |
+
import requests
|
5 |
+
|
6 |
+
# Load pre-trained model
|
7 |
+
classifier = pipeline("image-classification", model="Anwarkh1/Skin_Cancer-Image_Classification")
|
8 |
+
|
9 |
+
def classify_image(image):
|
10 |
+
results = classifier(image)
|
11 |
+
label = results[0]['label']
|
12 |
+
confidence = results[0]['score']
|
13 |
+
explanation = f"The model predicts **{label}** with a confidence of {confidence:.2%}."
|
14 |
+
return label, confidence, explanation
|
15 |
+
|
16 |
+
def fetch_research():
|
17 |
+
url = "https://api.semanticscholar.org/graph/v1/paper/search"
|
18 |
+
params = {"query": "cancer research", "fields": "title,abstract,url", "limit": 5}
|
19 |
+
response = requests.get(url, params=params)
|
20 |
+
papers = response.json().get("data", [])
|
21 |
+
return "\n".join([f"{paper['title']}: {paper['url']}" for paper in papers])
|
22 |
+
|
23 |
+
# Interface
|
24 |
+
with gr.Blocks() as demo:
|
25 |
+
gr.Markdown("# AI-Powered Universal Cancer Detection and Research Assistant 🌍🩺")
|
26 |
+
|
27 |
+
with gr.Tab("Cancer Detection"):
|
28 |
+
image = gr.Image(label="Upload Cancer Image")
|
29 |
+
label = gr.Textbox(label="Predicted Label")
|
30 |
+
confidence = gr.Slider(label="Confidence")
|
31 |
+
explanation = gr.Textbox(label="Explanation")
|
32 |
+
detect_btn = gr.Button("Classify")
|
33 |
+
detect_btn.click(classify_image, inputs=[image], outputs=[label, confidence, explanation])
|
34 |
+
|
35 |
+
with gr.Tab("Research Papers"):
|
36 |
+
fetch_btn = gr.Button("Fetch Research Papers")
|
37 |
+
papers = gr.Textbox(label="Latest Research Papers", lines=5)
|
38 |
+
fetch_btn.click(fetch_research, inputs=[], outputs=papers)
|
39 |
+
|
40 |
+
demo.launch()
|