Spaces:
Sleeping
Sleeping
runtime auth
Browse files
app.py
CHANGED
|
@@ -1,6 +1,13 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
# from huggingface_hub import InferenceClient
|
| 3 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
"""
|
| 6 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
|
@@ -8,7 +15,7 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 8 |
# requires space hardware update to use large models (TODO)
|
| 9 |
# client = InferenceClient("mistralai/Mistral-Large-Instruct-2407")
|
| 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
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
# from huggingface_hub import InferenceClient
|
| 3 |
from transformers import pipeline
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Retrieve the Hugging Face API token from environment variables
|
| 7 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 8 |
+
|
| 9 |
+
if not api_token:
|
| 10 |
+
raise ValueError("API token is not set. Please set the HF_TOKEN environment variable in Space Settings.")
|
| 11 |
|
| 12 |
"""
|
| 13 |
For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
|
|
|
|
| 15 |
# requires space hardware update to use large models (TODO)
|
| 16 |
# client = InferenceClient("mistralai/Mistral-Large-Instruct-2407")
|
| 17 |
# Note change in instantiation***
|
| 18 |
+
text_generator = pipeline("text-generation", model="google/gemma-2-2b", use_auth_token=hf_token)
|
| 19 |
|
| 20 |
def authenticate_and_generate(token, message, history, system_message, max_tokens, temperature, top_p):
|
| 21 |
# Initialize the text-generation pipeline with the provided token
|