Reality123b commited on
Commit
f944272
·
verified ·
1 Parent(s): 711f069

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
app.py CHANGED
@@ -1,15 +1,11 @@
1
  import gradio as gr
2
- import gradio as gr
3
  import os
4
  from huggingface_hub import InferenceClient
5
 
6
- # Read API key from environment variable
7
  hf_token = os.getenv("hf_token")
8
 
9
- # Initialize InferenceClient with the token from the environment
10
  client = InferenceClient(api_key=hf_token)
11
 
12
- # Function to get responses from the model
13
  def get_response(user_input):
14
  messages = [
15
  { "role": "system", "content": "you are xylaria 1.4 senoa, developed by sk md saad amin" },
@@ -30,16 +26,37 @@ def get_response(user_input):
30
  response += chunk.choices[0].delta.content
31
  return response
32
 
33
- # Set up the Gradio interface
34
- iface = gr.Interface(
35
- fn=get_response,
36
- inputs=gr.Textbox(label="Your message", placeholder="Type your message here..."),
37
- outputs=gr.Textbox(label="Response", interactive=False),
38
- title="Xylaria 1.4 Senoa Chatbot",
39
- description="A chatbot powered by Xylaria 1.4 Senoa, developed by Sk Md Saad Amin."
40
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
- # Launch the interface
43
- iface.launch()
 
 
44
 
45
- gr.load("models/Qwen/QwQ-32B-Preview").launch()
 
 
1
  import gradio as gr
 
2
  import os
3
  from huggingface_hub import InferenceClient
4
 
 
5
  hf_token = os.getenv("hf_token")
6
 
 
7
  client = InferenceClient(api_key=hf_token)
8
 
 
9
  def get_response(user_input):
10
  messages = [
11
  { "role": "system", "content": "you are xylaria 1.4 senoa, developed by sk md saad amin" },
 
26
  response += chunk.choices[0].delta.content
27
  return response
28
 
29
+ def chat_interface():
30
+ with gr.Blocks() as demo:
31
+ with gr.Row():
32
+ with gr.Column(scale=0.8):
33
+ input_textbox = gr.Textbox(
34
+ label="Type your message",
35
+ placeholder="Ask me anything...",
36
+ lines=1,
37
+ max_lines=3,
38
+ interactive=True,
39
+ elem_id="user-input",
40
+ show_label=False
41
+ )
42
+ with gr.Column(scale=0.2):
43
+ send_button = gr.Button("Send", elem_id="send-btn")
44
+
45
+ chat_output = gr.Chatbot(
46
+ elem_id="chat-box",
47
+ label="Xylaria 1.4 Senoa Chatbot",
48
+ show_label=False
49
+ )
50
+
51
+ def submit_input(user_input, chat_history):
52
+ response = get_response(user_input)
53
+ chat_history.append((user_input, response))
54
+ return "", chat_history
55
 
56
+ input_textbox.submit(submit_input, [input_textbox, chat_output], [input_textbox, chat_output])
57
+ send_button.click(submit_input, [input_textbox, chat_output], [input_textbox, chat_output])
58
+
59
+ return demo
60
 
61
+ demo = chat_interface()
62
+ demo.launch()