Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,63 @@
|
|
| 1 |
-
"""
|
| 2 |
# Inference
|
| 3 |
|
| 4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
app = gr.load(
|
| 7 |
"meta-llama/Llama-3.2-3B-Instruct",
|
| 8 |
src = "models",
|
|
|
|
|
|
|
| 1 |
# Inference
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
+
from huggingface_hub import InferenceClient
|
| 5 |
+
|
| 6 |
+
model = "meta-llama/Llama-3.2-3B-Instruct"
|
| 7 |
+
client = InferenceClient(model)
|
| 8 |
+
|
| 9 |
+
def fn(
|
| 10 |
+
message,
|
| 11 |
+
history: list[tuple[str, str]],
|
| 12 |
+
system_message,
|
| 13 |
+
max_tokens,
|
| 14 |
+
temperature,
|
| 15 |
+
top_p,
|
| 16 |
+
):
|
| 17 |
+
messages = [{"role": "system", "content": system_message}]
|
| 18 |
+
|
| 19 |
+
for val in history:
|
| 20 |
+
if val[0]:
|
| 21 |
+
messages.append({"role": "user", "content": val[0]})
|
| 22 |
+
if val[1]:
|
| 23 |
+
#messages.append({"role": "assistant", "content": val[1]})
|
| 24 |
+
messages.append({"role": "bot", "content": val[1]})
|
| 25 |
+
|
| 26 |
+
messages.append({"role": "user", "content": message})
|
| 27 |
+
|
| 28 |
+
response = ""
|
| 29 |
+
|
| 30 |
+
for message in client.chat_completion(
|
| 31 |
+
messages,
|
| 32 |
+
max_tokens = max_tokens,
|
| 33 |
+
temperature = temperature,
|
| 34 |
+
top_p = top_p,
|
| 35 |
+
stream = True,
|
| 36 |
+
):
|
| 37 |
+
token = message.choices[0].delta.content
|
| 38 |
+
|
| 39 |
+
response += token
|
| 40 |
+
yield response
|
| 41 |
|
| 42 |
+
app = gr.ChatInterface(
|
| 43 |
+
fn = fn,
|
| 44 |
+
additional_inputs = [
|
| 45 |
+
gr.Textbox(value="You are a friendly Chatbot.", label="System Message"),
|
| 46 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max Tokens"),
|
| 47 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 48 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-P"),
|
| 49 |
+
],
|
| 50 |
+
title = "Meta Llama",
|
| 51 |
+
description = model,
|
| 52 |
+
examples = [
|
| 53 |
+
["Hello, World."]
|
| 54 |
+
]
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
app.launch()
|
| 59 |
+
|
| 60 |
+
"""
|
| 61 |
app = gr.load(
|
| 62 |
"meta-llama/Llama-3.2-3B-Instruct",
|
| 63 |
src = "models",
|