PhaseDOutAI commited on
Commit
d1e98df
·
verified ·
1 Parent(s): ee81a61

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -53
app.py CHANGED
@@ -1,65 +1,42 @@
1
-
2
  import os
3
  import gradio as gr
4
  from huggingface_hub import InferenceClient
5
 
6
- # Hugging Face model + token
7
- HF_TOKEN = os.getenv("HF_TOKEN")
8
- MODEL = "openai/gpt-oss-20b"
9
- client = InferenceClient(token=HF_TOKEN, model=MODEL)
10
 
11
- # System prompt
12
- SYSTEM_PROMPT = "You are Persillia AI, a helpful chatbot that loves coding and airplanes."
 
 
 
13
 
14
- # Response generator
15
- def respond(message, history, temperature, top_p, max_tokens):
16
- messages = [{"role": "system", "content": SYSTEM_PROMPT}]
17
- for user, bot in history:
18
- messages.append({"role": "user", "content": user})
19
- messages.append({"role": "assistant", "content": bot})
20
  messages.append({"role": "user", "content": message})
21
 
22
  response = ""
23
- for msg in client.chat_completion(messages, max_tokens=max_tokens, temperature=temperature, top_p=top_p, stream=True):
24
- token = msg.choices[0].delta.content if msg.choices[0].delta and msg.choices[0].delta.content else ""
25
- response += token
26
- yield response
27
-
28
- # Gradio UI
29
- with gr.Blocks(css="""
30
- #chatbox {height: 600px; overflow-y: auto;}
31
- body {background: #101820; color: #f0f0f0; font-family: Arial;}
32
- .gr-button {background: #007bff; color: white; border-radius: 5px;}
33
- """) as demo:
34
- gr.Markdown("<h1 style='text-align:center;'>🚀 Persillia AI</h1>")
35
-
36
- chatbot = gr.Chatbot(elem_id="chatbox")
37
- msg = gr.Textbox(placeholder="Type your message here...")
38
- clear = gr.Button("Clear Chat")
39
-
40
- # Hidden tuning sliders
41
- with gr.Row(visible=False):
42
- temperature = gr.Slider(0, 1, value=0.7, step=0.05, label="Temperature")
43
- top_p = gr.Slider(0, 1, value=0.95, step=0.05, label="Top-p")
44
- max_tokens = gr.Slider(64, 1024, value=512, step=64, label="Max Tokens")
45
-
46
- # Handle input
47
- def user_submit(user_message, history):
48
- history = history + [[user_message, None]]
49
- return "", history
50
-
51
- def bot_response(history, temperature, top_p, max_tokens):
52
- user_message = history[-1][0]
53
- response = respond(user_message, history[:-1], temperature, top_p, max_tokens)
54
- for partial in response:
55
- history[-1][1] = partial
56
- yield history
57
-
58
- msg.submit(user_submit, [msg, chatbot], [msg, chatbot]).then(
59
- bot_response, [chatbot, temperature, top_p, max_tokens], chatbot
60
- )
61
-
62
- clear.click(lambda: [], None, chatbot, queue=False)
63
 
64
  if __name__ == "__main__":
65
  demo.launch()
 
 
1
  import os
2
  import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
 
 
 
 
5
 
6
+ def respond(message, history: list[dict[str, str]]):
7
+ # Fixed hidden system message
8
+ system_message = "You are a friendly Chatbot named Persillia AI. You love coding and talking about airplanes."
9
+
10
+ client = InferenceClient(model="openai/gpt-oss-20b")
11
 
12
+ # Build messages with hidden system
13
+ messages = [{"role": "system", "content": system_message}]
14
+ messages.extend(history)
 
 
 
15
  messages.append({"role": "user", "content": message})
16
 
17
  response = ""
18
+ for msg in client.chat_completion(
19
+ messages,
20
+ max_tokens=512, # hidden setting
21
+ stream=True,
22
+ temperature=0.7, # hidden setting
23
+ top_p=0.95, # hidden setting
24
+ ):
25
+ choices = msg.choices
26
+ if choices and choices[0].delta.content:
27
+ response += choices[0].delta.content
28
+ yield response
29
+
30
+
31
+ chatbot = gr.ChatInterface(
32
+ respond,
33
+ type="messages",
34
+ )
35
+
36
+ with gr.Blocks(css=".gradio-container {background-color: #0d1117; color: white;}") as demo:
37
+ gr.Markdown("<h1 style='text-align:center;'>✈️ Persillia AI</h1>")
38
+ with gr.Row():
39
+ chatbot.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  if __name__ == "__main__":
42
  demo.launch()