Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -49,20 +49,19 @@ HF_API_KEY = os.getenv("HF_API_KEY")
|
|
49 |
if HF_API_KEY is None:
|
50 |
raise ValueError("HF_API_KEY environment variable is not set.")
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
55 |
|
56 |
# π· Wrap HF client into LangChain LLM interface
|
57 |
class HuggingFaceInferenceLLM(LLM):
|
58 |
"""LLM that queries HuggingFace Inference API."""
|
59 |
|
60 |
-
model: str = HF_MODEL
|
61 |
client: InferenceClient = client
|
62 |
|
63 |
def _call(self, prompt, stop=None, run_manager=None, **kwargs):
|
64 |
response = self.client.text_generation(
|
65 |
-
self.model,
|
66 |
prompt,
|
67 |
max_new_tokens=512,
|
68 |
temperature=0.7,
|
@@ -104,4 +103,4 @@ with gr.Blocks() as demo:
|
|
104 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False)
|
105 |
clear.click(lambda: None, None, chatbot, queue=False)
|
106 |
|
107 |
-
demo.launch(debug=True
|
|
|
49 |
if HF_API_KEY is None:
|
50 |
raise ValueError("HF_API_KEY environment variable is not set.")
|
51 |
|
52 |
+
HF_MODEL = "deepseek-ai/deepseek-llm-7b-instruct" # or any other hosted model
|
53 |
+
|
54 |
+
# π€ Create InferenceClient bound to model
|
55 |
+
client = InferenceClient(model=HF_MODEL, token=HF_API_KEY)
|
56 |
|
57 |
# π· Wrap HF client into LangChain LLM interface
|
58 |
class HuggingFaceInferenceLLM(LLM):
|
59 |
"""LLM that queries HuggingFace Inference API."""
|
60 |
|
|
|
61 |
client: InferenceClient = client
|
62 |
|
63 |
def _call(self, prompt, stop=None, run_manager=None, **kwargs):
|
64 |
response = self.client.text_generation(
|
|
|
65 |
prompt,
|
66 |
max_new_tokens=512,
|
67 |
temperature=0.7,
|
|
|
103 |
msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False)
|
104 |
clear.click(lambda: None, None, chatbot, queue=False)
|
105 |
|
106 |
+
demo.launch(debug=True) # remove share=True if running in HF Spaces
|