Spaces:
Sleeping
Sleeping
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() | |