yumyum2081 commited on
Commit
c5890c9
·
verified ·
1 Parent(s): 26a4b07

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -1
app.py CHANGED
@@ -1,3 +1,51 @@
1
  import gradio as gr
 
 
2
 
3
- gr.load("models/meta-llama/Llama-3.2-3B").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import AutoModelForCausalLM, AutoTokenizer
3
+ import torch
4
 
5
+ # Load the model and tokenizer
6
+ tokenizer = AutoTokenizer.from_pretrained("meta-llama/Llama-3.2-3B")
7
+ model = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-3.2-3B")
8
+
9
+ def predict(input_text):
10
+ """Generate a response using the Llama model."""
11
+ inputs = tokenizer.encode(input_text, return_tensors="pt")
12
+ outputs = model.generate(inputs, max_length=150, num_return_sequences=1)
13
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+
15
+ # Metadata
16
+ title = "Llama 3.2-3B Model Demonstration"
17
+ description = """
18
+ ## How to Use
19
+ 1. Enter a prompt in the input box.
20
+ 2. Click 'Submit' to get the model's response.
21
+ 3. Explore the examples provided for inspiration.
22
+
23
+ ## Model Details
24
+ - **Name:** Llama 3.2-3B
25
+ - **Capabilities:** Text generation, summarization, translation, etc.
26
+
27
+ This Space demonstrates the capabilities of Meta's Llama 3.2-3B model.
28
+ """
29
+ examples = [
30
+ ["Generate a summary for: Artificial intelligence is the simulation of human intelligence..."],
31
+ ["Translate the text: Hello, how are you? into French."],
32
+ ["What are the benefits of renewable energy sources?"],
33
+ ["Write a poem about the ocean."],
34
+ ]
35
+
36
+ # Interface
37
+ def create_interface():
38
+ """Create a Gradio interface for the Llama model."""
39
+ return gr.Interface(
40
+ fn=predict,
41
+ inputs=gr.Textbox(lines=5, placeholder="Type your input here...", label="Enter your prompt"),
42
+ outputs=gr.Textbox(label="Model Output"),
43
+ title=title,
44
+ description=description,
45
+ examples=examples,
46
+ theme="compact"
47
+ )
48
+
49
+ # Launch the interface
50
+ interface = create_interface()
51
+ interface.launch(share=True, server_name="0.0.0.0")