File size: 2,604 Bytes
3ad4486
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2007180
3ad4486
 
 
 
 
 
 
 
1af75b6
2007180
1af75b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2007180
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import gradio as gr
import requests

# Define Hugging Face API endpoint and token
API_URL = "https://api-inference.huggingface.co/models/facebook/bart-large-cnn"
API_TOKEN = "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"  # Replace with your actual token

# Function to query Hugging Face API for text summarization
def query_summarization(input_text):
    headers = {
        "Authorization": f"Bearer {API_TOKEN}",
        "Content-Type": "application/json",
    }
    payload = {
        "inputs": input_text
    }
    try:
        # Sending POST request to the Hugging Face API
        response = requests.post(API_URL, headers=headers, json=payload)
        response.raise_for_status()  # Raise error for bad responses (4xx, 5xx)
        result = response.json()

        # Extract and return the summary
        if result and "summary_text" in result[0]:
            return result[0]["summary_text"]
        else:
            return "Sorry, an error occurred. Please try again later."
    except requests.exceptions.RequestException as e:
        return f"Error: {e}"

# Custom CSS styling
custom_css = """
#input-text {
    font-size: 18px;
    border: 2px solid #8a2be2;
    border-radius: 10px;
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
}

#summary-output {
    font-size: 18px;
    border: 2px solid #8a2be2;
    border-radius: 10px;
    padding: 15px;
    width: 100%;
    box-sizing: border-box;
    background-color: #f4f4f9;
    color: #333;
}

h1 {
    text-align: center;
    font-size: 3em;
    color: #8a2be2;
    margin-bottom: 30px;
}

.gradio-container {
    background-color: #f5f5f5;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0px 10px 20px rgba(0, 0, 0, 0.1);
}

.gradio-container .output-textbox {
    font-family: "Arial", sans-serif;
    color: #333;
    font-size: 16px;
}

.gradio-container .input-textbox {
    font-family: "Arial", sans-serif;
    font-size: 16px;
}
"""

# Create Gradio interface with custom CSS
iface = gr.Interface(
    fn=query_summarization,  # Function to call
    inputs=gr.Textbox(
        lines=10, 
        placeholder="Enter your text here...", 
        label="Input Text",
        elem_id="input-text"
    ),  # Input text area
    outputs=gr.Textbox(
        placeholder="Summary will appear here...", 
        label="Summary",
        elem_id="summary-output"
    ),  # Output summary text
    title="AI Text Summarization",
    description="Enter text to get a summarized version using Hugging Face's BART model.",
    css=custom_css  # Apply custom CSS here
)

# Launch the interface
iface.launch(share=True)