Mahmoud Amiri commited on
Commit
a256d3e
·
1 Parent(s): dc732ec

change chat completion to text to text

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -13,29 +13,25 @@ def respond(
13
  hf_token: gr.OAuthToken,
14
  ):
15
  """
16
- Sends a chat message to the Hugging Face Inference API using the provided token and parameters.
17
  """
18
  client = InferenceClient(
19
  token=hf_token.token,
20
  model="Bocklitz-Lab/lit2vec-tldr-bart-model"
21
  )
22
 
23
- messages = [{"role": "system", "content": system_message}] + history
24
- messages.append({"role": "user", "content": message})
25
 
26
- response = ""
27
-
28
- for message_chunk in client.chat_completion(
29
- messages,
30
- max_tokens=max_tokens,
31
- stream=True,
32
  temperature=temperature,
33
- top_p=top_p,
34
- ):
35
- if message_chunk.choices and message_chunk.choices[0].delta.content:
36
- token = message_chunk.choices[0].delta.content
37
- response += token
38
- yield response
39
 
40
  # Define the Gradio interface
41
  chatbot = gr.ChatInterface(
 
13
  hf_token: gr.OAuthToken,
14
  ):
15
  """
16
+ Sends a user input to the summarization model using text-to-text interface.
17
  """
18
  client = InferenceClient(
19
  token=hf_token.token,
20
  model="Bocklitz-Lab/lit2vec-tldr-bart-model"
21
  )
22
 
23
+ # You can prepend the system message if needed
24
+ input_text = f"{system_message}\n\n{message}"
25
 
26
+ response = client.text_to_text(
27
+ input=input_text,
28
+ max_new_tokens=max_tokens,
 
 
 
29
  temperature=temperature,
30
+ top_p=top_p
31
+ )
32
+
33
+ yield response
34
+
 
35
 
36
  # Define the Gradio interface
37
  chatbot = gr.ChatInterface(