Instructions to use Rakshitaa/Text_summarization with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Rakshitaa/Text_summarization with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "summarization" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # pip install "transformers<5.0.0" from transformers import pipeline pipe = pipeline("summarization", model="Rakshitaa/Text_summarization")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForSeq2SeqLM tokenizer = AutoTokenizer.from_pretrained("Rakshitaa/Text_summarization") model = AutoModelForSeq2SeqLM.from_pretrained("Rakshitaa/Text_summarization", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download gradio_implementation.py from Rakshitaa/Text_summarization: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/Rakshitaa/Text_summarization/resolve/main/gradio_implementation.py
- Command line
-
hf download hf://Rakshitaa/Text_summarization/gradio_implementation.py
-
curl -L -o gradio_implementation.py https://huggingface.co/Rakshitaa/Text_summarization/resolve/main/gradio_implementation.py
1.46 kB
| # -*- coding: utf-8 -*- | |
| """gradio-implementation.ipynb | |
| Automatically generated by Colaboratory. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1sWjE9rMmM4iMx2Gy5880k53D7yaRfDge | |
| """ | |
| pip install gradio | |
| pip install gTTS | |
| pip install translate | |
| pip install transformers | |
| import gradio as gr | |
| from transformers import pipeline | |
| from gtts import gTTS | |
| from translate import Translator | |
| # Initialize the text summarization pipeline | |
| summarizer = pipeline("summarization") | |
| # Define the Gradio interface | |
| def summarize_and_translate(article, target_language): | |
| # Summarize the input article | |
| summary = summarizer(article, max_length=130, min_length=30, do_sample=False)[0]['summary_text'] | |
| # Translate the summary to the target language | |
| translator = Translator(to_lang=target_language) | |
| translated_summary = translator.translate(summary) | |
| # Convert the translated summary to speech | |
| tts = gTTS(text=translated_summary, lang=target_language) | |
| tts.save("speech.mp3") | |
| # Return the summarized text and the path to the generated speech | |
| return translated_summary, "speech.mp3" | |
| # Create a Gradio interface | |
| iface = gr.Interface( | |
| fn=summarize_and_translate, | |
| inputs=["text", "text"], | |
| outputs=["text", "audio"], | |
| layout="vertical", | |
| title="Text Summarization and Translation", | |
| description="Summarize text and translate it into another language.", | |
| ) | |
| # Start the Gradio interface | |
| iface.launch() |