neuralworm commited on
Commit
fdae6e7
·
verified ·
1 Parent(s): 810d58b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -1,20 +1,31 @@
1
  import gradio as gr
2
  from huggingface_hub.utils import HfHubHTTPError
3
 
 
4
  def predict(message, history):
5
  try:
6
- # Load the model and create a prediction function
7
- iface = gr.Interface.load("models/meta-llama/Meta-Llama-3.1-8B")
8
- fn = iface.launch(share=False,prevent_thread_lock=True)
9
- response = fn(message) # Get the prediction using the function
 
 
 
 
 
 
 
 
10
  history.append((message, response))
11
  return "", history
 
12
  except HfHubHTTPError as e:
13
  if e.response.status_code == 504:
14
  return "Server overloaded. Please try again later.", history
15
  else:
16
  raise e
17
 
 
18
  with gr.Blocks() as demo:
19
  chatbot = gr.Chatbot()
20
  msg = gr.Textbox()
 
1
  import gradio as gr
2
  from huggingface_hub.utils import HfHubHTTPError
3
 
4
+
5
  def predict(message, history):
6
  try:
7
+ # Create the Interface object directly
8
+ iface = gr.Interface(
9
+ fn=gr.ChatInterface.load("models/meta-llama/Meta-Llama-3.1-8B"),
10
+ inputs="textbox",
11
+ outputs="textbox",
12
+ )
13
+
14
+ # Launch the interface and get the prediction function
15
+ with iface:
16
+ fn = iface.predict
17
+
18
+ response = fn(message, history)
19
  history.append((message, response))
20
  return "", history
21
+
22
  except HfHubHTTPError as e:
23
  if e.response.status_code == 504:
24
  return "Server overloaded. Please try again later.", history
25
  else:
26
  raise e
27
 
28
+
29
  with gr.Blocks() as demo:
30
  chatbot = gr.Chatbot()
31
  msg = gr.Textbox()