suwesh commited on
Commit
4208c01
Β·
verified Β·
1 Parent(s): fa279dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -22
app.py CHANGED
@@ -6,7 +6,7 @@ from transformers import pipeline
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
7
  """
8
  #client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
-
10
  modelpath = "distilgpt2"
11
 
12
  pipe = pipeline(
@@ -44,29 +44,19 @@ def respond(
44
  except Exception as e:
45
  return f"Error: {str(e)}"
46
 
47
- try:
48
- response = pipe(
49
- messages,
50
- max_new_tokens=max_tokens,
51
- temperature=temperature,
52
- top_p=top_p,
53
- )[0]["generated_text"]
54
- yield response
55
- except Exception as e:
56
- return f"Error: {str(e)}"
57
- #response = ""
58
 
59
- #for message in client.chat_completion(
60
- # messages,
61
- # max_tokens=max_tokens,
62
- # stream=True,
63
- # temperature=temperature,
64
- # top_p=top_p,
65
- #):
66
- # token = message.choices[0].delta.content
67
 
68
- # response += token
69
- # yield response
70
 
71
 
72
  """
 
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
7
  """
8
  #client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
+ client = InferenceClient("distilbert/distilgpt2")
10
  modelpath = "distilgpt2"
11
 
12
  pipe = pipeline(
 
44
  except Exception as e:
45
  return f"Error: {str(e)}"
46
 
47
+ response = ""
 
 
 
 
 
 
 
 
 
 
48
 
49
+ for message in client.chat_completion(
50
+ messages,
51
+ max_tokens=max_tokens,
52
+ stream=True,
53
+ temperature=temperature,
54
+ top_p=top_p,
55
+ ):
56
+ token = message.choices[0].delta.content
57
 
58
+ response += token
59
+ yield response
60
 
61
 
62
  """