ahmedtaj commited on
Commit
a8dfc2f
·
verified ·
1 Parent(s): 03b6b4e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datasets import load_dataset
3
+ import pandas as pd
4
+
5
+ # Load dataset
6
+ dataset = load_dataset('dell-research-harvard/newswire', split='train')
7
+
8
+ # Function to filter and match articles
9
+ def filter_nobel_articles(laureates_file):
10
+ laureates_df = pd.read_csv(laureates_file.name)
11
+ nobel_articles = dataset.filter(lambda example: 'nobel' in example['text'].lower())
12
+
13
+ def contains_laureate(article_text):
14
+ for _, row in laureates_df.iterrows():
15
+ if row['first_name'] in article_text and row['last_name'] in article_text:
16
+ return True
17
+ return False
18
+
19
+ filtered_articles = nobel_articles.filter(lambda example: contains_laureate(example['text']))
20
+ return f"Found {len(filtered_articles)} articles mentioning Nobel laureates."
21
+
22
+ # Create Gradio interface
23
+ interface = gr.Interface(
24
+ fn=filter_nobel_articles,
25
+ inputs=gr.File(label="Upload Nobel Laureates CSV"),
26
+ outputs="text"
27
+ )
28
+
29
+ interface.launch()