File size: 1,640 Bytes
06b57f4
 
 
 
 
db88443
06b57f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
db88443
06b57f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr
from transformers import pipeline
from PIL import Image
import requests

# Load pre-trained model for cancer image classification
classifier = pipeline("image-classification", model="Anwarkh1/Skin_Cancer-Image_Classification")

def classify_image(image):
    results = classifier(image)
    label = results[0]['label']
    confidence = results[0]['score']
    explanation = f"The model predicts **{label}** with a confidence of {confidence:.2%}."
    return label, confidence, explanation

def fetch_research():
    url = "https://api.semanticscholar.org/graph/v1/paper/search"
    params = {"query": "cancer research", "fields": "title,abstract,url", "limit": 5}
    response = requests.get(url, params=params)
    papers = response.json().get("data", [])
    return "\n".join([f"{paper['title']}: {paper['url']}" for paper in papers])

# Gradio Interface
with gr.Blocks() as demo:
    gr.Markdown("# AI-Powered Universal Cancer Detection and Research Assistant ๐ŸŒ๐Ÿฉบ")
    
    with gr.Tab("Cancer Detection"):
        image = gr.Image(label="Upload Cancer Image")
        label = gr.Textbox(label="Predicted Label")
        confidence = gr.Slider(label="Confidence")
        explanation = gr.Textbox(label="Explanation")
        detect_btn = gr.Button("Classify")
        detect_btn.click(classify_image, inputs=[image], outputs=[label, confidence, explanation])
    
    with gr.Tab("Research Papers"):
        fetch_btn = gr.Button("Fetch Research Papers")
        papers = gr.Textbox(label="Latest Research Papers", lines=5)
        fetch_btn.click(fetch_research, inputs=[], outputs=papers)
    
demo.launch()