Spaces:
Sleeping
Sleeping
introduce auth
Browse files
app.py
CHANGED
|
@@ -10,13 +10,16 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 10 |
# Note change in instantiation***
|
| 11 |
text_generator = pipeline("text-generation", model="google/gemma-2-2b")
|
| 12 |
|
| 13 |
-
def
|
|
|
|
|
|
|
|
|
|
| 14 |
# Construct the prompt with system message, history, and user input
|
| 15 |
prompt = system_message + "\n" + "\n".join([f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history if msg[0] and msg[1]])
|
| 16 |
prompt += f"\nUser: {message}\nAssistant:"
|
| 17 |
|
| 18 |
# Generate a response using the model
|
| 19 |
-
response = text_generator(prompt, max_length=max_tokens, temperature=temperature, top_p=top_p, do_sample=True, truncation=
|
| 20 |
|
| 21 |
# Extract the generated text from the response list
|
| 22 |
assistant_response = response[0]['generated_text']
|
|
@@ -28,8 +31,15 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
| 28 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 29 |
"""
|
| 30 |
athena = gr.ChatInterface(
|
| 31 |
-
fn=
|
| 32 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
gr.Textbox(value=
|
| 34 |
"""
|
| 35 |
You are a marketing-minded content writer for Plan.com (a UK telecommunications company).
|
|
|
|
| 10 |
# Note change in instantiation***
|
| 11 |
text_generator = pipeline("text-generation", model="google/gemma-2-2b")
|
| 12 |
|
| 13 |
+
def authenticate_and_generate(token, message, history, system_message, max_tokens, temperature, top_p):
|
| 14 |
+
# Initialize the text-generation pipeline with the provided token
|
| 15 |
+
text_generator = pipeline("text-generation", model="google/gemma-2-2b", use_auth_token=token)
|
| 16 |
+
|
| 17 |
# Construct the prompt with system message, history, and user input
|
| 18 |
prompt = system_message + "\n" + "\n".join([f"User: {msg[0]}\nAssistant: {msg[1]}" for msg in history if msg[0] and msg[1]])
|
| 19 |
prompt += f"\nUser: {message}\nAssistant:"
|
| 20 |
|
| 21 |
# Generate a response using the model
|
| 22 |
+
response = text_generator(prompt, max_length=max_tokens, temperature=temperature, top_p=top_p, do_sample=True, truncation=True)
|
| 23 |
|
| 24 |
# Extract the generated text from the response list
|
| 25 |
assistant_response = response[0]['generated_text']
|
|
|
|
| 31 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 32 |
"""
|
| 33 |
athena = gr.ChatInterface(
|
| 34 |
+
fn=authenticate_and_generate,
|
| 35 |
additional_inputs=[
|
| 36 |
+
gr.Textbox(
|
| 37 |
+
label="Hugging Face API Token",
|
| 38 |
+
type="password",
|
| 39 |
+
placeholder="Please provide a Hugging Face auth token.",
|
| 40 |
+
lines=1,
|
| 41 |
+
max_lines=1
|
| 42 |
+
),
|
| 43 |
gr.Textbox(value=
|
| 44 |
"""
|
| 45 |
You are a marketing-minded content writer for Plan.com (a UK telecommunications company).
|