Update app.py
Browse files
app.py
CHANGED
|
@@ -5,12 +5,12 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
|
|
| 5 |
# Define the BLOOM model name
|
| 6 |
model_name = "CreitinGameplays/bloom-3b-conversational"
|
| 7 |
|
| 8 |
-
# Load tokenizer and model
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
|
| 12 |
def generate_text(user_prompt):
|
| 13 |
-
"""Generates text using the BLOOM model
|
| 14 |
# Construct the full prompt with system introduction, user prompt, and assistant role
|
| 15 |
prompt = f"<|system|> You are a helpful AI assistant. </s> <|prompter|> {user_prompt} </s> <|assistant|>"
|
| 16 |
|
|
@@ -24,7 +24,7 @@ def generate_text(user_prompt):
|
|
| 24 |
num_beams=1,
|
| 25 |
num_return_sequences=1,
|
| 26 |
do_sample=True,
|
| 27 |
-
top_k=
|
| 28 |
top_p=0.95,
|
| 29 |
temperature=0.2,
|
| 30 |
repetition_penalty=1.155
|
|
@@ -40,7 +40,7 @@ def generate_text(user_prompt):
|
|
| 40 |
|
| 41 |
return assistant_response
|
| 42 |
|
| 43 |
-
# Define the Gradio interface
|
| 44 |
interface = gr.Interface(
|
| 45 |
fn=generate_text,
|
| 46 |
inputs=[
|
|
@@ -48,6 +48,7 @@ interface = gr.Interface(
|
|
| 48 |
],
|
| 49 |
outputs="text",
|
| 50 |
description="Interact with BLOOM-3b-conversational (Loaded with Hugging Face Transformers)",
|
|
|
|
| 51 |
)
|
| 52 |
|
| 53 |
# Launch the Gradio interface
|
|
|
|
| 5 |
# Define the BLOOM model name
|
| 6 |
model_name = "CreitinGameplays/bloom-3b-conversational"
|
| 7 |
|
| 8 |
+
# Load tokenizer and model (outside the function for efficiency)
|
| 9 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
model = AutoModelForCausalLM.from_pretrained(model_name)
|
| 11 |
|
| 12 |
def generate_text(user_prompt):
|
| 13 |
+
"""Generates text using the pre-loaded BLOOM model and removes the user prompt."""
|
| 14 |
# Construct the full prompt with system introduction, user prompt, and assistant role
|
| 15 |
prompt = f"<|system|> You are a helpful AI assistant. </s> <|prompter|> {user_prompt} </s> <|assistant|>"
|
| 16 |
|
|
|
|
| 24 |
num_beams=1,
|
| 25 |
num_return_sequences=1,
|
| 26 |
do_sample=True,
|
| 27 |
+
top_k=50,
|
| 28 |
top_p=0.95,
|
| 29 |
temperature=0.2,
|
| 30 |
repetition_penalty=1.155
|
|
|
|
| 40 |
|
| 41 |
return assistant_response
|
| 42 |
|
| 43 |
+
# Define the Gradio interface with live=True for real-time updates
|
| 44 |
interface = gr.Interface(
|
| 45 |
fn=generate_text,
|
| 46 |
inputs=[
|
|
|
|
| 48 |
],
|
| 49 |
outputs="text",
|
| 50 |
description="Interact with BLOOM-3b-conversational (Loaded with Hugging Face Transformers)",
|
| 51 |
+
live=True
|
| 52 |
)
|
| 53 |
|
| 54 |
# Launch the Gradio interface
|