Vinit710 commited on
Commit
40c7962
·
verified ·
1 Parent(s): 9314635

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -10
app.py CHANGED
@@ -1,10 +1,16 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
 
3
 
4
- """
5
- 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
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
 
8
 
9
 
10
  def respond(
@@ -35,13 +41,10 @@ def respond(
35
  top_p=top_p,
36
  ):
37
  token = message.choices[0].delta.content
38
-
39
  response += token
40
  yield response
41
 
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
  demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
@@ -58,6 +61,5 @@ demo = gr.ChatInterface(
58
  ],
59
  )
60
 
61
-
62
  if __name__ == "__main__":
63
- demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ import os
4
+ from dotenv import load_dotenv
5
 
6
+ # Load environment variables from a .env file if available
7
+ load_dotenv()
8
+
9
+ # Read your Hugging Face token from an environment variable
10
+ HF_TOKEN = os.getenv("HF_TOKEN")
11
+
12
+ # Initialize client with token
13
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta", token=HF_TOKEN)
14
 
15
 
16
  def respond(
 
41
  top_p=top_p,
42
  ):
43
  token = message.choices[0].delta.content
 
44
  response += token
45
  yield response
46
 
47
+
 
 
48
  demo = gr.ChatInterface(
49
  respond,
50
  additional_inputs=[
 
61
  ],
62
  )
63
 
 
64
  if __name__ == "__main__":
65
+ demo.launch()