Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,18 +11,16 @@ text_generation_pipeline = pipeline(
|
|
11 |
"text-generation",
|
12 |
model=model_name,
|
13 |
model_kwargs={"torch_dtype": "auto", "load_in_4bit": True},
|
14 |
-
use_auth_token=hf_token
|
15 |
)
|
16 |
|
17 |
def generate_text(user_input):
|
18 |
messages = [{"role": "user", "content": user_input}]
|
19 |
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
20 |
-
# Notice: No `use_auth_token` here. It's only needed when loading the model initially.
|
21 |
outputs = text_generation_pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
22 |
return outputs[0]["generated_text"]
|
23 |
|
24 |
-
|
25 |
-
# Create the Gradio interface without the unsupported argument
|
26 |
iface = gr.Interface(
|
27 |
fn=generate_text,
|
28 |
inputs=gr.Textbox(lines=2, placeholder="Type your question here..."),
|
@@ -31,6 +29,5 @@ iface = gr.Interface(
|
|
31 |
description="A text generation model that understands your queries and generates concise, informative responses."
|
32 |
)
|
33 |
|
34 |
-
# Launch the interface
|
35 |
-
iface.launch(
|
36 |
-
|
|
|
11 |
"text-generation",
|
12 |
model=model_name,
|
13 |
model_kwargs={"torch_dtype": "auto", "load_in_4bit": True},
|
14 |
+
use_auth_token=hf_token # Correctly placed for model and tokenizer loading
|
15 |
)
|
16 |
|
17 |
def generate_text(user_input):
|
18 |
messages = [{"role": "user", "content": user_input}]
|
19 |
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
|
|
20 |
outputs = text_generation_pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
21 |
return outputs[0]["generated_text"]
|
22 |
|
23 |
+
# Create the Gradio interface
|
|
|
24 |
iface = gr.Interface(
|
25 |
fn=generate_text,
|
26 |
inputs=gr.Textbox(lines=2, placeholder="Type your question here..."),
|
|
|
29 |
description="A text generation model that understands your queries and generates concise, informative responses."
|
30 |
)
|
31 |
|
32 |
+
# Launch the interface (omit `share=True` when deploying on Hugging Face Spaces)
|
33 |
+
iface.launch()
|
|