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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -0
app.py CHANGED
@@ -1,3 +1,45 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  gr.load("models/Qwen/QwQ-32B-Preview").launch()
 
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" },
16
+ { "role": "user", "content": user_input }
17
+ ]
18
+
19
+ stream = client.chat.completions.create(
20
+ model="Qwen/QwQ-32B-Preview",
21
+ messages=messages,
22
+ temperature=0.5,
23
+ max_tokens=10240,
24
+ top_p=0.7,
25
+ stream=True
26
+ )
27
+
28
+ response = ""
29
+ for chunk in stream:
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()