ronylu commited on
Commit
dc59429
·
verified ·
1 Parent(s): 025b552

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from huggingface_hub import InferenceClient
4
+
5
+ MODEL_ID = "meta-llama/Meta-Llama-3.1-8B-Instruct"
6
+ SYSTEM_PROMPT = "You are a helpful assistant."
7
+
8
+ client = InferenceClient(model=MODEL_ID, token=os.getenv("HF_TOKEN"))
9
+
10
+ def respond(message, history):
11
+ # history is OpenAI-style messages when using type="messages"
12
+ messages = [{"role": "system", "content": SYSTEM_PROMPT}]
13
+ messages.extend(history)
14
+ messages.append({"role": "user", "content": message})
15
+
16
+ out = client.chat_completion(
17
+ messages=messages,
18
+ max_tokens=400,
19
+ temperature=0.7,
20
+ )
21
+ return out.choices[0].message.content
22
+
23
+ demo = gr.ChatInterface(
24
+ fn=respond,
25
+ type="messages",
26
+ title="Llama 3.1 Chatbot (HF Space)",
27
+ )
28
+
29
+ demo.launch()