Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,29 @@
|
|
1 |
import os
|
2 |
-
import
|
3 |
-
from dotenv import load_dotenv, find_dotenv
|
4 |
-
import requests, json
|
5 |
from transformers import pipeline
|
6 |
import gradio as gr
|
7 |
-
from transformers import pipeline
|
8 |
|
|
|
9 |
load_dotenv()
|
10 |
|
11 |
-
# Access the Hugging Face API key
|
12 |
hf_api_key = os.getenv('HF_API_KEY')
|
13 |
-
#Summarization endpoint
|
14 |
-
get_completion = pipeline("summarization", model="shleifer/distilbart-cnn-12-6", token=hf_api_key)
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
|
|
20 |
demo = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
21 |
demo.launch()
|
|
|
1 |
import os
|
2 |
+
from dotenv import load_dotenv
|
|
|
|
|
3 |
from transformers import pipeline
|
4 |
import gradio as gr
|
|
|
5 |
|
6 |
+
# Load environment variables
|
7 |
load_dotenv()
|
8 |
|
9 |
+
# Access the Hugging Face API key
|
10 |
hf_api_key = os.getenv('HF_API_KEY')
|
|
|
|
|
11 |
|
12 |
+
# Initialize the summarization pipeline
|
13 |
+
summarizer = pipeline(
|
14 |
+
"summarization",
|
15 |
+
model="sshleifer/distilbart-cnn-12-6", # Corrected model name
|
16 |
+
token=hf_api_key
|
17 |
+
)
|
18 |
+
|
19 |
+
def summarize(input_text):
|
20 |
+
try:
|
21 |
+
# Limit input text to 1024 tokens to avoid potential issues
|
22 |
+
output = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
|
23 |
+
return output[0]['summary_text']
|
24 |
+
except Exception as e:
|
25 |
+
return f"An error occurred: {str(e)}"
|
26 |
|
27 |
+
# Create and launch the Gradio interface
|
28 |
demo = gr.Interface(fn=summarize, inputs="text", outputs="text")
|
29 |
demo.launch()
|