Spaces:
Sleeping
Sleeping
File size: 1,214 Bytes
d70e310 c245a44 d70e310 c245a44 d70e310 c245a44 d70e310 c245a44 d70e310 c245a44 d70e310 c245a44 d70e310 c245a44 |
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 |
import gradio as gr
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# Load the tokenizer and model from Hugging Face
model_name = "waterdrops0/mistral-nouns600"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(model_name, device_map="auto", torch_dtype=torch.float16)
def generate_text(prompt, max_length=50, temperature=0.7):
inputs = tokenizer.encode(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
inputs,
max_length=max_length,
temperature=temperature,
do_sample=True,
top_p=0.95,
top_k=60
)
text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return text
iface = gr.Interface(
fn=generate_text,
inputs=[
gr.inputs.Textbox(lines=2, placeholder="Enter your prompt here..."),
gr.inputs.Slider(10, 200, step=10, default=50, label="Max Length"),
gr.inputs.Slider(0.1, 1.0, step=0.1, default=0.7, label="Temperature")
],
outputs="text",
title="Mistral 7B Nouns Model",
description="Generate text using the fine-tuned Mistral 7B model."
)
if __name__ == "__main__":
iface.launch()
|