Spaces:
Sleeping
Sleeping
File size: 1,070 Bytes
fc52c32 3e47c44 6d602ad 3e47c44 a8c702d 3e47c44 e7a3aa2 3e47c44 7abb300 3e47c44 7abb300 3e47c44 fc52c32 3e47c44 |
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 |
import gradio as gr
from transformers import LlamaTokenizer, LlamaForCausalLM, pipeline
import torch
# Load your model and tokenizer
model_name = "midrees2806/2Krows_uoe_edu"
tokenizer = LlamaTokenizer.from_pretrained(model_name)
model = LlamaForCausalLM.from_pretrained(model_name,torch_dtype=torch.float16,device_map="cpu")
# Define the pipeline
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer)
def generate_response(prompt):
# Format the prompt as required by the model
input_text = f"<s>[INST] {prompt} [/INST]"
# Generate response with max_new_tokens specified
response = pipe(input_text, max_new_tokens=50) # Adjust 50 as needed
# Extract the generated text from the response
answer = response[0]['generated_text'].split('[/INST]')[-1].strip()
return answer
# Gradio Interface setup
iface = gr.Interface(
fn=generate_response,
inputs="text",
outputs="text",
title="LLaMA-2 Chatbot",
description="Ask anything to the LLaMA-2 fine-tuned model!",
)
# Launch the Gradio app
iface.launch()
|