Spaces:
Sleeping
Sleeping
File size: 2,229 Bytes
87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 87edca7 3244390 |
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
import gradio as gr
import arxiv
from transformers import pipeline
# Load summarization model
summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
# Search and summarize papers
def search_and_summarize(topic, sort_by_option):
try:
num_papers = 3 # fixed value
sort_mapping = {
"Relevance": arxiv.SortCriterion.Relevance,
"Most Recent": arxiv.SortCriterion.SubmittedDate
}
search = arxiv.Search(
query=topic,
max_results=num_papers,
sort_by=sort_mapping.get(sort_by_option, arxiv.SortCriterion.Relevance)
)
results = []
for result in search.results():
summary = summarizer(result.summary[:1000], max_length=120, min_length=30, do_sample=False)[0]['summary_text']
authors = ", ".join([author.name for author in result.authors])
published_date = result.published.date().strftime("%Y-%m-%d")
result_block = (
f"📘 *{result.title}*\n\n"
f"👩🔬 Authors: {authors}\n"
f"📅 Published: {published_date}\n\n"
f"📝 Summary: {summary}\n\n"
f"🔗 [Read More]({result.pdf_url})"
)
results.append(result_block)
return "\n\n---\n\n".join(results) if results else "No results found."
except Exception as e:
return f"⚠️ An error occurred: {e}"
# Gradio UI
with gr.Blocks(theme=gr.themes.Base()) as demo:
gr.Markdown("# 🤖 AI Research Assistant\nSummarize academic research papers using Hugging Face models + Arxiv!")
with gr.Row():
topic = gr.Textbox(label="🔍 Enter your research topic", placeholder="e.g. diffusion models in AI")
sort_by = gr.Dropdown(choices=["Relevance", "Most Recent"], value="Relevance", label="Sort by")
search_btn = gr.Button("Search 🔎")
output = gr.Markdown()
# Show loading message
def show_loading():
return "⏳ Loading, please wait..."
search_btn.click(fn=show_loading, inputs=[], outputs=output, queue=False)
search_btn.click(fn=search_and_summarize, inputs=[topic, sort_by], outputs=output)
demo.launch() |