Pavithiran commited on
Commit
4635a0c
·
verified ·
1 Parent(s): c07b25b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
- from typing import List, Tuple
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
@@ -9,9 +8,9 @@ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
 
10
 
11
  def respond(
12
- message: str,
13
- history: List[Tuple[str, str]],
14
- system_message: str,
15
  max_tokens=1024,
16
  temperature=0.7,
17
  top_p=0.95,
@@ -36,13 +35,12 @@ def respond(
36
  temperature=temperature,
37
  top_p=top_p,
38
  ):
39
- if message.choices and "delta" in message.choices[0]:
40
- token = message.choices[0].delta.get("content", "")
41
- response += token
42
- yield response
43
- except Exception as e:
44
- print(f"Error during API call: {e}")
45
- yield "An error occurred while processing the request."
46
 
47
  """
48
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
@@ -65,4 +63,4 @@ demo = gr.ChatInterface(
65
 
66
 
67
  if __name__ == "__main__":
68
- demo.launch()
 
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
 
8
 
9
 
10
  def respond(
11
+ message,
12
+ history: list[tuple[str, str]],
13
+ system_message,
14
  max_tokens=1024,
15
  temperature=0.7,
16
  top_p=0.95,
 
35
  temperature=temperature,
36
  top_p=top_p,
37
  ):
38
+ token = message.choices[0].delta.content
39
+
40
+ response += token
41
+ yield response
42
+ except json.JSONDecodeError as e:
43
+ yield f"Error: {e}"
 
44
 
45
  """
46
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
63
 
64
 
65
  if __name__ == "__main__":
66
+ demo.launch()