LovnishVerma commited on
Commit
46c8cfc
1 Parent(s): ff9f2fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -13
app.py CHANGED
@@ -1,17 +1,32 @@
1
- import gradio as gr
 
2
 
3
- # Load the fine-tuned Llama 2 model
4
- model = "models/mlabonne/llama-2-7b-guanaco"
5
 
6
- # Create a Gradio interface
7
- iface = gr.Interface(
8
- fn=model, # Use the fine-tuned Llama 2 model as the function
9
- inputs="text", # Input is text
10
- outputs="text", # Output is also text
11
- live=True, # Enable live updates without button click
12
- theme="compact", # Use a compact theme for the interface
13
- description="Fine-tuned Llama 2: Enter a prompt to get a model-generated response."
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  )
15
 
16
- # Launch the Gradio app
17
- iface.launch()
 
 
1
+ # Install necessary libraries
2
+ # !pip install transformers
3
 
4
+ from transformers import AutoTokenizer, pipeline
5
+ import torch
6
 
7
+ # Model and prompt details
8
+ model_name = "mlabonne/llama-2-7b-guanaco"
9
+ prompt = "What is a large language model?"
10
+
11
+ # Load tokenizer and pipeline
12
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
13
+ text_generation_pipeline = pipeline(
14
+ "text-generation",
15
+ model=model_name,
16
+ torch_dtype=torch.float16,
17
+ device_map="auto",
18
+ )
19
+
20
+ # Generate text using the provided prompt
21
+ sequences = text_generation_pipeline(
22
+ f'<s>[INST] {prompt} [/INST]',
23
+ do_sample=True,
24
+ top_k=10,
25
+ num_return_sequences=1,
26
+ eos_token_id=tokenizer.eos_token_id,
27
+ max_length=200,
28
  )
29
 
30
+ # Print the generated text
31
+ for seq in sequences:
32
+ print(f"Generated Text: {seq['generated_text']}")