tdecae commited on
Commit
2ceeece
Β·
verified Β·
1 Parent(s): 5ed3b00

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
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
- # πŸ€– Use HuggingFace Inference API (cloud) for LLM
53
- HF_MODEL = "deepseek-ai/deepseek-llm-7b-instruct" # change if desired
54
- client = InferenceClient(token=HF_API_KEY)
 
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, share=True) # share=True gives you a public link
 
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