AirrStorm commited on
Commit
d1d897c
·
1 Parent(s): c934690

Adding application file

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ def summarizer(sentence, min_length, max_length):
5
+ model_name = "/home/airrstorm/Documents/Python/Hugging-Face/Models/T5-Small-XSUM-Summarizer"
6
+
7
+ # Create a summarization pipeline with the local model
8
+ summarizer = pipeline("summarization", model=model_name, tokenizer=model_name)
9
+
10
+ summary = summarizer(
11
+ sentence,
12
+ max_length=int(max_length), # Convert to int for Gradio input compatibility
13
+ min_length=int(min_length), # Convert to int for Gradio input compatibility
14
+ length_penalty=1.2, # Length penalty for beam search
15
+ num_beams=4, # Number of beams for beam search
16
+ early_stopping=True # Stop early when an optimal summary is found
17
+ )
18
+ return summary[0]["summary_text"]
19
+
20
+ # Define inputs for the Gradio interface with better layout and styling
21
+ inputs = [
22
+ gr.Textbox(
23
+ label="Input Text",
24
+ lines=10,
25
+ placeholder="Enter the text to summarize here...",
26
+ interactive=True,
27
+ elem_id="input_text_box"
28
+ ),
29
+ gr.Number(
30
+ label="Minimum Length",
31
+ value=50,
32
+ precision=0,
33
+ interactive=True,
34
+ elem_id="min_length"
35
+ ),
36
+ gr.Number(
37
+ label="Maximum Length",
38
+ value=200,
39
+ precision=0,
40
+ interactive=True,
41
+ elem_id="max_length"
42
+ ),
43
+ ]
44
+
45
+ # Define the Gradio interface
46
+ demo = gr.Interface(
47
+ fn=summarizer,
48
+ inputs=inputs,
49
+ outputs=gr.Textbox(
50
+ label="Summary",
51
+ lines=6,
52
+ placeholder="Your summary will appear here.",
53
+ interactive=False,
54
+ elem_id="output_summary"
55
+ ),
56
+ title="Text Summarization Tool",
57
+ description="Provide a text input, specify the minimum and maximum lengths for the summary, and get a concise version of your text.",
58
+ theme="huggingface", # Optional, you can change to other themes like 'compact'
59
+ allow_flagging="never", # Disable flagging
60
+ )
61
+
62
+ # Launch the interface with shareable link
63
+ demo.launch(share=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ SentencePiece
4
+ sacremoses