Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,22 +2,38 @@ import gradio as gr
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
|
| 5 |
-
# Load Falcon-7B-Instruct model
|
| 6 |
model_id = "tiiuae/falcon-7b-instruct"
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
-
model = AutoModelForCausalLM.from_pretrained(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
# Function to generate response
|
| 11 |
def generate_response(prompt):
|
| 12 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
-
outputs = model.generate(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 15 |
|
| 16 |
# Gradio interface
|
| 17 |
iface = gr.Interface(
|
| 18 |
fn=generate_response,
|
| 19 |
-
inputs=gr.Textbox(label="Enter your prompt"),
|
| 20 |
outputs=gr.Textbox(label="Zephyrix Response"),
|
| 21 |
-
title="Zephyrix - Pakistan's First AI Model"
|
|
|
|
| 22 |
)
|
| 23 |
-
|
|
|
|
|
|
|
|
|
| 2 |
from transformers import AutoTokenizer, AutoModelForCausalLM
|
| 3 |
import torch
|
| 4 |
|
| 5 |
+
# Load Falcon-7B-Instruct model with 4-bit quantization
|
| 6 |
model_id = "tiiuae/falcon-7b-instruct"
|
| 7 |
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 8 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 9 |
+
model_id,
|
| 10 |
+
torch_dtype=torch.float16,
|
| 11 |
+
device_map="auto",
|
| 12 |
+
load_in_4bit=True,
|
| 13 |
+
trust_remote_code=True
|
| 14 |
+
)
|
| 15 |
|
| 16 |
# Function to generate response
|
| 17 |
def generate_response(prompt):
|
| 18 |
inputs = tokenizer(prompt, return_tensors="pt").to("cuda" if torch.cuda.is_available() else "cpu")
|
| 19 |
+
outputs = model.generate(
|
| 20 |
+
**inputs,
|
| 21 |
+
max_length=100,
|
| 22 |
+
do_sample=True,
|
| 23 |
+
top_k=50,
|
| 24 |
+
top_p=0.95,
|
| 25 |
+
num_return_sequences=1
|
| 26 |
+
)
|
| 27 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 28 |
|
| 29 |
# Gradio interface
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=generate_response,
|
| 32 |
+
inputs=gr.Textbox(label="Enter your prompt", placeholder="Type here..."),
|
| 33 |
outputs=gr.Textbox(label="Zephyrix Response"),
|
| 34 |
+
title="Zephyrix - Pakistan's First AI Model",
|
| 35 |
+
description="Built with love in Pakistan!"
|
| 36 |
)
|
| 37 |
+
|
| 38 |
+
# Launch app
|
| 39 |
+
iface.launch(server_name="0.0.0.0", server_port=7860)
|