File size: 982 Bytes
fc52c32
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
import gradio as gr
from transformers import LlamaTokenizer, LlamaForCausalLM, pipeline

# Load your model and tokenizer
model_name = "midrees2806/Llama-2-7b-updatedchatbot-finetune"
tokenizer = LlamaTokenizer.from_pretrained(model_name)
model = LlamaForCausalLM.from_pretrained(model_name)

# Define the pipeline
pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer)

# Define the function to generate responses
def generate_response(prompt):
    # Format the prompt as required by the model
    input_text = f"<s>[INST] {prompt} [/INST]"
    response = pipe(input_text)
    # 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()