amkyawdev commited on
Commit
345d602
·
verified ·
1 Parent(s): 44970d9

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -1,18 +1,20 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Use a model that supports text-generation
5
  client = InferenceClient("meta-llama/Llama-3.2-1B-Instruct")
6
 
7
  def generate(prompt, temperature=0.8, max_tokens=256):
8
  try:
9
- response = client.text_generation(
10
- prompt=prompt,
 
 
11
  temperature=temperature,
12
- max_new_tokens=max_tokens,
13
  do_sample=True if temperature > 0 else False
14
  )
15
- return response
16
  except Exception as e:
17
  return f"Error: {str(e)}"
18
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Use conversational endpoint
5
  client = InferenceClient("meta-llama/Llama-3.2-1B-Instruct")
6
 
7
  def generate(prompt, temperature=0.8, max_tokens=256):
8
  try:
9
+ # Use conversational instead of text_generation
10
+ messages = [{"role": "user", "content": prompt}]
11
+ response = client.chat_completion(
12
+ messages=messages,
13
  temperature=temperature,
14
+ max_tokens=max_tokens,
15
  do_sample=True if temperature > 0 else False
16
  )
17
+ return response.choices[0].message.content
18
  except Exception as e:
19
  return f"Error: {str(e)}"
20