Spaces:
Runtime error
Runtime error
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() | |