File size: 2,698 Bytes
c8085f8
 
 
 
 
4cd520b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7f4a5e2
c8085f8
7f4a5e2
c8085f8
7f4a5e2
c8085f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4cd520b
 
 
 
 
 
 
 
 
 
 
c8085f8
 
 
 
 
 
 
 
 
 
003093c
c8085f8
 
 
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Use a pipeline as a high-level helper
from transformers import pipeline
import torch
import gradio as gr

from huggingface_hub import CommitScheduler
from pathlib import Path

import os
import uuid
import joblib
import json

# Prepare the logging functionality

log_file = Path("logs/") / f"data_{uuid.uuid4()}.json"
log_folder = log_file.parent

scheduler = CommitScheduler(
    repo_id="text-summarization-logs",
    repo_type="dataset",
    folder_path=log_folder,
    path_in_repo="data",
    every=2
)


text_summary = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6", torch_dtype=torch.bfloat16)

# model_path = "Model/models--sshleifer--distilbart-cnn-12-6/snapshots/a4f8f3ea906ed274767e9906dbaede7531d660ff"

# text_summary = pipeline("summarization", model=model_path, torch_dtype=torch.bfloat16)

# text="Why You Can Trust Forbes Advisor Small Business \
# The Forbes Advisor Small Business team is committed to bringing you unbiased \
# rankings and information with full editorial independence. We use product data, \
# strategic methodologies and expert insights to inform all of our content and guide \
# you in making the best decisions for your business journey.\
# We reviewed 11 systems to help you find the best blogging platform for your blog or \
# small business. Our ratings looked at factors that included the platform’s starting \
# price (including whether it offered a free trial or free version); useful general features,\
# such as drag-and-drop functionality and search engine optimization (SEO) tools; unique features, \
# how well the blogging platform fared on third-party review sites and a final review by our experts.\
# All ratings are determined solely by our editorial team."

# print(text_summary(text)[0])

def summary(input):
    output = text_summary(input)

    with scheduler.lock:
        with log_file.open("a") as f:
            f.write(json.dumps(
                {
                    'Input Text': input,
                    'Summary':output[0]['summary_text']
                }
            ))
            f.write("\n")
    
    return output[0]['summary_text']

gr.close_all()

# demo = gr.Interface(fn=summary,inputs="text",outputs='text',title='Text Summarization Gradio Huggingface')
demo = gr.Interface(fn=summary,
                    inputs=[gr.Textbox(label="Input text to summarization", lines=6)],
                    outputs=[gr.Textbox(label="Summarized text", lines=4)],
                    title='Text Summarization',
                    description='This application will be used to summarize the text',
                    theme=gr.themes.Soft(),
                    concurrency_limit=16)

demo.launch(share=True)