Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -1,18 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
# Use
|
| 5 |
client = InferenceClient("meta-llama/Llama-3.2-1B-Instruct")
|
| 6 |
|
| 7 |
def generate(prompt, temperature=0.8, max_tokens=256):
|
| 8 |
try:
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
temperature=temperature,
|
| 12 |
-
|
| 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 |
|