Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
|
43 |
-
|
|
|
|
|
44 |
|
45 |
-
|
|
|
|
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()
|