JohnKouf commited on
Commit
04627a4
·
verified ·
1 Parent(s): da39e44

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +75 -26
app.py CHANGED
@@ -1,35 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
- from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
3
-
4
- # Load the model and tokenizer
5
- model_name = 'IMISLab/GreekT5-umt5-base-greeksum'
6
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
-
9
- # Set up the summarizer pipeline
10
- summarizer = pipeline(
11
- 'summarization',
12
- model=model,
13
- tokenizer=tokenizer,
14
- device=-1, # -1 for CPU; set to 0 for GPU if available
15
- max_new_tokens=128,
16
- truncation=True
17
- )
18
 
19
- # Define the summarization function
20
- def summarize_text(text):
21
- output = summarizer('summarize: ' + text)
22
- return output[0]['summary_text']
23
 
24
- # Create a Gradio interface
 
 
 
 
 
25
  iface = gr.Interface(
26
- fn=summarize_text, # Function to run
27
- inputs=gr.Textbox(label="Enter Greek Text", placeholder="Type or paste your text here..."), # Input component
28
  outputs=gr.Textbox(label="Summary", interactive=True), # Output component
29
- title="Greek Text Summarization", # Title for the UI
30
- description="This app uses a pre-trained Greek summarization model to generate a brief summary of your input text.", # Description
31
- allow_flagging="never" # Optional: Disable flagging feature
32
  )
33
 
34
  # Launch the interface
35
  iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import gradio as gr
2
+ # from transformers import AutoModelForSeq2SeqLM, AutoTokenizer, pipeline
3
+
4
+ # # Load the model and tokenizer
5
+ # model_name = 'IMISLab/GreekT5-umt5-base-greeksum'
6
+ # model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
+ # tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ # # Set up the summarizer pipeline
10
+ # summarizer = pipeline(
11
+ # 'summarization',
12
+ # model=model,
13
+ # tokenizer=tokenizer,
14
+ # device=-1, # -1 for CPU; set to 0 for GPU if available
15
+ # max_new_tokens=128,
16
+ # truncation=True
17
+ # )
18
+
19
+ # # Define the summarization function
20
+ # def summarize_text(text):
21
+ # output = summarizer('summarize: ' + text)
22
+ # return output[0]['summary_text']
23
+
24
+ # # Create a Gradio interface
25
+ # iface = gr.Interface(
26
+ # fn=summarize_text, # Function to run
27
+ # inputs=gr.Textbox(label="Enter Greek Text", placeholder="Type or paste your text here..."), # Input component
28
+ # outputs=gr.Textbox(label="Summary", interactive=True), # Output component
29
+ # title="Greek Text Summarization", # Title for the UI
30
+ # description="This app uses a pre-trained Greek summarization model to generate a brief summary of your input text.", # Description
31
+ # allow_flagging="never" # Optional: Disable flagging feature
32
+ # )
33
+
34
+ # # Launch the interface
35
+ # iface.launch()
36
+
37
  import gradio as gr
38
+ from transformers import pipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
40
+ # Load the summarizer model
41
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
 
 
42
 
43
+ # Function to summarize text
44
+ def summarize_text(article):
45
+ summary = summarizer(article, max_length=130, min_length=30, do_sample=False)
46
+ return summary[0]['summary_text']
47
+
48
+ # Create the Gradio interface
49
  iface = gr.Interface(
50
+ fn=summarize_text, # The function to be called
51
+ inputs=gr.Textbox(label="Enter Article Text", placeholder="Type or paste the article here..."), # Input component
52
  outputs=gr.Textbox(label="Summary", interactive=True), # Output component
53
+ title="Text Summarization", # Title of the interface
54
+ description="This app uses a pre-trained summarization model (BART) to summarize the provided article.", # Description
55
+ allow_flagging="never" # Disable flagging
56
  )
57
 
58
  # Launch the interface
59
  iface.launch()
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+