thamile commited on
Commit
8b831d6
·
verified ·
1 Parent(s): 0638681

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -1,14 +1,14 @@
1
  import gradio as gr
2
- from embraceface_hub import InferenceClient
3
 
4
- # Initialize the model client
5
- client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct")
6
 
7
  # Maximum number of messages to keep in history
8
  MAX_HISTORY = 10
9
 
10
  def chat_fn(message, history):
11
- # Convert history to the correct format for the model
12
  messages = []
13
  for user_msg, bot_msg in history[-MAX_HISTORY:]: # Keep only the last MAX_HISTORY messages
14
  messages.append({"role": "user", "content": user_msg})
@@ -17,8 +17,9 @@ def chat_fn(message, history):
17
  # Add the new user message
18
  messages.append({"role": "user", "content": message})
19
 
20
- # Call the model
21
- response = client.chat_completion(
 
22
  messages=messages,
23
  max_tokens=300
24
  )
@@ -37,6 +38,4 @@ with gr.Blocks() as demo:
37
  gr.Markdown("# 💬 JuriX Chatbot")
38
  chatbot = gr.Chatbot()
39
  msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
40
- msg.submit(chat_fn, [msg, chatbot], [msg, chatbot])
41
-
42
- demo.launch()
 
1
  import gradio as gr
2
+ import openai
3
 
4
+ # Set your OpenAI API key
5
+ openai.api_key = "YOUR_API_KEY" # Replace with your actual API key
6
 
7
  # Maximum number of messages to keep in history
8
  MAX_HISTORY = 10
9
 
10
  def chat_fn(message, history):
11
+ # Convert history to the correct format for OpenAI
12
  messages = []
13
  for user_msg, bot_msg in history[-MAX_HISTORY:]: # Keep only the last MAX_HISTORY messages
14
  messages.append({"role": "user", "content": user_msg})
 
17
  # Add the new user message
18
  messages.append({"role": "user", "content": message})
19
 
20
+ # Call OpenAI API
21
+ response = openai.ChatCompletion.create(
22
+ model="gpt-3.5-turbo",
23
  messages=messages,
24
  max_tokens=300
25
  )
 
38
  gr.Markdown("# 💬 JuriX Chatbot")
39
  chatbot = gr.Chatbot()
40
  msg = gr.Textbox(label="Type your message here", placeholder="Enter your message...")
41
+ msg.submit(chat_fn, [msg, chat]()_