0906harika commited on
Commit
230653e
·
verified ·
1 Parent(s): 2fbd3a6

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +58 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import BartTokenizer, BartForConditionalGeneration
4
+
5
+ # Initialize tokenizers and models for both healthcare and AI
6
+ healthcare_model_name = 'facebook/bart-large-cnn'
7
+ ai_model_name = 'facebook/bart-large-xsum'
8
+
9
+ healthcare_tokenizer = BartTokenizer.from_pretrained(healthcare_model_name)
10
+ ai_tokenizer = BartTokenizer.from_pretrained(ai_model_name)
11
+
12
+ healthcare_model = BartForConditionalGeneration.from_pretrained(healthcare_model_name)
13
+ ai_model = BartForConditionalGeneration.from_pretrained(ai_model_name)
14
+
15
+ # Summarization function
16
+ def generate_summary(text, tokenizer, model):
17
+ inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True, padding="max_length")
18
+ with torch.no_grad():
19
+ outputs = model.generate(inputs["input_ids"], max_length=150, num_beams=5, no_repeat_ngram_size=2, early_stopping=True)
20
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
21
+
22
+ # Functions for each agent
23
+ def healthcare_agent(abstract):
24
+ return generate_summary(abstract, healthcare_tokenizer, healthcare_model)
25
+
26
+ def ai_agent(abstract):
27
+ return generate_summary(abstract, ai_tokenizer, ai_model)
28
+
29
+ # Function to generate implications based on both agents' insights
30
+ def generate_implications(healthcare_summary, ai_summary):
31
+ healthcare_implication = f"Healthcare Implications: {healthcare_summary} The healthcare sector can leverage these findings to improve patient care and treatment outcomes."
32
+ ai_implication = f"AI Implications: {ai_summary} These insights can further enhance AI models, making them more applicable in real-world healthcare scenarios."
33
+ combined_implications = f"{healthcare_implication}\n\n{ai_implication}"
34
+ return combined_implications
35
+
36
+ # Gradio Interface function
37
+ def summarize_and_generate_implications(abstract):
38
+ healthcare_summary = healthcare_agent(abstract)
39
+ ai_summary = ai_agent(abstract)
40
+ implications = generate_implications(healthcare_summary, ai_summary)
41
+ return healthcare_summary, ai_summary, implications
42
+
43
+ # Creating the Gradio interface
44
+ interface = gr.Interface(
45
+ fn=summarize_and_generate_implications,
46
+ inputs=gr.Textbox(label="Abstract", placeholder="Enter the abstract of a research paper..."),
47
+ outputs=[
48
+ gr.Textbox(label="Healthcare Summary"),
49
+ gr.Textbox(label="AI Summary"),
50
+ gr.Textbox(label="Implications")
51
+ ],
52
+ live=True,
53
+ title="Research Paper Summarization and Implications",
54
+ description="This app generates summaries for healthcare and AI domains and provides implications for each."
55
+ )
56
+
57
+ # Launch the Gradio interface
58
+ interface.launch(share=True) # share=True will generate a public link
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ gradio
4
+ pandas