Satyam-Singh commited on
Commit
8562d5d
1 Parent(s): 0a12784

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -13
app.py CHANGED
@@ -1,22 +1,25 @@
1
  import gradio as gr
2
- from transformers import pipeline
3
 
4
- # Load the Meta-Llama-3.1-8B-Instruct-GGUF model
5
  model_name = "lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF"
6
- model = pipeline("text-generation", model=model_name, device=-1) # -1 for CPU
 
7
 
8
- # Define the Gradio interface
9
  def generate_text(prompt):
10
- output = model(prompt)[0]["generated_text"]
11
- return output
 
12
 
13
- iface = gr.Interface(
14
- fn=generate_text,
15
- inputs=gr.Textbox(label="Prompt"),
16
- outputs=gr.Textbox(label="Generated Text"),
17
- title="Meta-Llama-3.1-8B-Instruct-GGUF Text Generation",
18
- description="Enter a prompt to generate text using the Meta-Llama-3.1-8B-Instruct-GGUF model.",
 
19
  )
20
 
21
  # Launch the Gradio app
22
- iface.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
 
4
+ # Load the GGUF model and tokenizer
5
  model_name = "lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForCausalLM.from_pretrained(model_name)
8
 
9
+ # Define a function to generate text using the GGUF model
10
  def generate_text(prompt):
11
+ inputs = tokenizer.encode(prompt, return_tensors="pt")
12
+ outputs = model.generate(inputs, max_length=50)
13
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
14
 
15
+ # Create a Gradio chatbot interface
16
+ chatbot = gr.Chatbot(
17
+ generate_text,
18
+ title="GGUF Chatbot",
19
+ description="Talk to the GGUF model!",
20
+ width=800,
21
+ height=600,
22
  )
23
 
24
  # Launch the Gradio app
25
+ chatbot.launch()