Instructions to use DisgustingOzil/Mistral_summarizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DisgustingOzil/Mistral_summarizer with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("DisgustingOzil/Mistral_summarizer", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- Unsloth Studio new
How to use DisgustingOzil/Mistral_summarizer with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for DisgustingOzil/Mistral_summarizer to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for DisgustingOzil/Mistral_summarizer to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for DisgustingOzil/Mistral_summarizer to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="DisgustingOzil/Mistral_summarizer", max_seq_length=2048, )
Model Card for Model ID
Requirements
!pip install gradio
!pip install -U xformers --index-url https://download.pytorch.org/whl/cu121
!pip install "unsloth[kaggle-new] @ git+https://github.com/unslothai/unsloth.git"
import os
os.environ["WANDB_DISABLED"] = "true"
Gradio App
import gradio as gr
from transformers import AutoTokenizer
from peft import AutoPeftModelForCausalLM
import torch
import anthropic
# Assuming the model and tokenizer for Mistral are correctly set up as per your provided code.
# Let's also assume you have a way to call the Anthropic model, perhaps via an API or another library.
load_in_4bit = True
model = AutoPeftModelForCausalLM.from_pretrained(
"DisgustingOzil/Mistral_summarizer",
load_in_4bit=load_in_4bit,
torch_dtype=torch.float16,
).to("cuda")
tokenizer = AutoTokenizer.from_pretrained("DisgustingOzil/Mistral_summarizer")
def summarize_with_mistral(text):
summary_prompt = f"""Below is a text that needs to be summarized. Based on the input, write a good summary which summarize all main points.
### Text:
{text}
### Summary:
""" # The summary part is left empty for generation
inputs = tokenizer([summary_prompt], return_tensors="pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens=150, use_cache=True)
summary = tokenizer.batch_decode(outputs, skip_special_tokens=True)
summary_start_index = summary[0].find("### Summary:")
summary_text = summary[0][summary_start_index:].replace("### Summary:", "").strip()
return summary_text
summary_1=""
def summarize_with_anthropic(text):
API_KEY="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"
client = anthropic.Anthropic(
# defaults to os.environ.get("ANTHROPIC_API_KEY")
api_key=API_KEY,
)
message = client.messages.create(
model="claude-3-haiku-20240307",
max_tokens=3214,
temperature=0,
system="Create Good summary explaining all key points in detail, easy and understandable way",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": text
}
]
}
]
)
# Placeholder function to represent summarization with an Anthropic model.
# This should be replaced with actual API calls or function calls to the Anthropic model.
# summary_1=message.content[0]
summary=message.content[0]
return summary.text
def summarize_text(text, model_choice):
if model_choice == "Mistral 7b":
return summarize_with_mistral(text)
elif model_choice == "Claude-3-Haiku":
return summarize_with_anthropic(text)
else:
return "Invalid model choice."
# Define the Gradio interface with a dropdown for model selection
iface = gr.Interface(
fn=summarize_text,
inputs=[gr.Textbox(lines=10, label="Input Text"), gr.Dropdown(choices=["Mistral 7b", "Claude-3-Haiku"], label="Model Choice")],
outputs=gr.Textbox(label="Summary"),
title="Text Summarization",
description="Enter text to summarize based on Maxwell's equations and related concepts. Select a model for summarization."
)
# Launch the app
if __name__ == "__main__":
iface.launch(debug=True)
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support