back to square 1
Browse files
app.py
CHANGED
@@ -1,33 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
-
import os
|
4 |
-
from dotenv import load_dotenv
|
5 |
from fastapi import FastAPI
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
AUTH_TOKEN = os.getenv("HUGGINGFACE_AUTH_TOKEN")
|
11 |
|
12 |
# Define the summarization function
|
13 |
def summarize_text(input_text):
|
14 |
-
|
15 |
-
|
16 |
-
"Content-Type": "application/json"
|
17 |
-
}
|
18 |
-
data = {
|
19 |
-
"data": [input_text] # Ensure input is in the expected format
|
20 |
-
}
|
21 |
-
|
22 |
-
try:
|
23 |
-
response = requests.post(f"{HUGGINGFACE_API_URL}/api/predict", json=data, headers=headers)
|
24 |
-
response.raise_for_status() # Raise an error for bad responses
|
25 |
-
result = response.json()
|
26 |
-
return result["data"][0] # Extract the summary from the response
|
27 |
-
except requests.exceptions.HTTPError as err:
|
28 |
-
return f"Error: {err.response.status_code} - {err.response.text}"
|
29 |
-
except Exception as e:
|
30 |
-
return f"An error occurred: {str(e)}"
|
31 |
|
32 |
# Create the Gradio app
|
33 |
app = gr.Interface(
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
|
|
|
|
3 |
from fastapi import FastAPI
|
4 |
|
5 |
+
# Initialize the summarization pipeline
|
6 |
+
summarizer = pipeline("summarization", model="RMWeerasinghe/text_summarization-finetuned_cnn_dailymail")
|
7 |
+
|
|
|
8 |
|
9 |
# Define the summarization function
|
10 |
def summarize_text(input_text):
|
11 |
+
summary = summarizer(input_text, max_length=600, min_length=30, do_sample=False)
|
12 |
+
return summary[0]['summary_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Create the Gradio app
|
15 |
app = gr.Interface(
|