cetusian commited on
Commit
c4d2bd1
1 Parent(s): dd449af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -2,10 +2,12 @@ import os
2
  import gradio as gr
3
  from huggingface_hub import login
4
  from huggingface_hub import InferenceClient
5
- import spaces
6
 
 
7
  api_key = os.getenv("LLAMA")
8
  login(api_key)
 
 
9
  client = InferenceClient("meta-llama/Llama-3.1-70B-Instruct")
10
 
11
  def respond(
@@ -27,10 +29,7 @@ def respond(
27
 
28
  response = ""
29
 
30
- # Move the model to GPU for inference
31
- client.model.to("cuda")
32
-
33
- # Generate the response from the model
34
  for message in client.chat_completion(
35
  messages,
36
  max_tokens=max_tokens,
@@ -39,16 +38,13 @@ def respond(
39
  top_p=top_p,
40
  ):
41
  token = message.choices[0].delta.content
42
-
43
  response += token
44
  yield response
45
 
46
- client.model.to("cpu")
47
-
48
  # Initialize the Gradio ChatInterface with the new format
49
  demo = gr.ChatInterface(
50
  respond,
51
- type="messages", # Use the new OpenAI-style format
52
  additional_inputs=[
53
  gr.Textbox(
54
  value="You are a helpful Customer Support assistant that specializes in the low-code software company: 'Plant an App' and tech-related topics.",
 
2
  import gradio as gr
3
  from huggingface_hub import login
4
  from huggingface_hub import InferenceClient
 
5
 
6
+ # Retrieve API key and authenticate
7
  api_key = os.getenv("LLAMA")
8
  login(api_key)
9
+
10
+ # Initialize InferenceClient for the Llama model
11
  client = InferenceClient("meta-llama/Llama-3.1-70B-Instruct")
12
 
13
  def respond(
 
29
 
30
  response = ""
31
 
32
+ # Send the conversation to the model and stream the response
 
 
 
33
  for message in client.chat_completion(
34
  messages,
35
  max_tokens=max_tokens,
 
38
  top_p=top_p,
39
  ):
40
  token = message.choices[0].delta.content
 
41
  response += token
42
  yield response
43
 
 
 
44
  # Initialize the Gradio ChatInterface with the new format
45
  demo = gr.ChatInterface(
46
  respond,
47
+ type="messages", # Use the OpenAI-style format
48
  additional_inputs=[
49
  gr.Textbox(
50
  value="You are a helpful Customer Support assistant that specializes in the low-code software company: 'Plant an App' and tech-related topics.",