Ramaravind commited on
Commit
08c411e
·
verified ·
1 Parent(s): ca57ad0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -8
app.py CHANGED
@@ -7,12 +7,17 @@ MODEL = "bigscience/bloom-560m" #"microsoft/Phi-3-mini-128k-instruct"
7
 
8
  # Initialize the InferenceClient with the token and model.
9
  # Using a lightweight model like google/flan-t5-small.
 
 
 
 
10
  client = InferenceClient(
11
- "google/flan-t5-small",
12
- token=HF_API_TOKEN
13
  )
14
 
15
 
 
16
  # -------------------------
17
  # Core function: call HF API
18
  # -------------------------
@@ -23,13 +28,25 @@ def query_llm(tweet, mode):
23
  else:
24
  prompt += "Task: Is the above TEXT toxic? First clearly state your decision. Then, provide specific reason(s) for your decision. If there is more than one reason, provide them in a numbered list. Your reason(s) must be non-redundant and jointly sufficient to justify your decision. In other words, there should not be any internal or external information unused in your explanation."
25
 
26
- # Use the client to generate text from the full prompt.
27
- response = client.text_generation(
28
- prompt=prompt,
29
- max_new_tokens=250, # Control the length of the generated output.
30
- stream=False, # Set to True for streaming responses.
 
 
 
 
 
 
 
 
 
 
 
31
  )
32
- return response
 
33
 
34
  # -------------------------
35
  # Preloaded tweets
 
7
 
8
  # Initialize the InferenceClient with the token and model.
9
  # Using a lightweight model like google/flan-t5-small.
10
+ # client = InferenceClient(
11
+ # "google/flan-t5-small",
12
+ # token=HF_API_TOKEN
13
+ # )
14
  client = InferenceClient(
15
+ provider="nebius",
16
+ api_key=HF_API_TOKEN
17
  )
18
 
19
 
20
+
21
  # -------------------------
22
  # Core function: call HF API
23
  # -------------------------
 
28
  else:
29
  prompt += "Task: Is the above TEXT toxic? First clearly state your decision. Then, provide specific reason(s) for your decision. If there is more than one reason, provide them in a numbered list. Your reason(s) must be non-redundant and jointly sufficient to justify your decision. In other words, there should not be any internal or external information unused in your explanation."
30
 
31
+ # # Use the client to generate text from the full prompt.
32
+ # response = client.text_generation(
33
+ # prompt=prompt,
34
+ # max_new_tokens=250, # Control the length of the generated output.
35
+ # stream=False, # Set to True for streaming responses.
36
+ # )
37
+ # return response
38
+
39
+ completion = client.chat.completions.create(
40
+ model="google/gemma-2-2b-it",
41
+ messages=[
42
+ {
43
+ "role": "user",
44
+ "content": prompt
45
+ }
46
+ ],
47
  )
48
+ return completion.choices[0].message['content']
49
+
50
 
51
  # -------------------------
52
  # Preloaded tweets