Pagn13 commited on
Commit
7d02efe
·
verified ·
1 Parent(s): 63360c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
+
4
+ client = InferenceClient(model="openai/gpt-oss-20b") # No token
5
+
6
+ def respond(message, history, system_message, max_tokens, temperature, top_p):
7
+ messages = [{"role": "system", "content": system_message}]
8
+ messages += history
9
+ messages.append({"role": "user", "content": message})
10
+
11
+ response = ""
12
+ try:
13
+ for chunk in client.chat_completion(
14
+ messages=messages,
15
+ max_tokens=max_tokens,
16
+ stream=True,
17
+ temperature=temperature,
18
+ top_p=top_p,
19
+ ):
20
+ if hasattr(chunk.choices[0].delta, "content"):
21
+ token = chunk.choices[0].delta.content
22
+ response += token
23
+ yield response
24
+ except Exception as e:
25
+ yield f"⚠️ Error: {e}"
26
+
27
+ chatbot = gr.ChatInterface(
28
+ fn=respond,
29
+ additional_inputs=[
30
+ gr.Textbox(value="You are a helpful assistant.", label="System Message"),
31
+ gr.Slider(minimum=64, maximum=2048, value=512, step=1, label="Max Tokens"),
32
+ gr.Slider(minimum=0.1, maximum=1.5, value=0.7, step=0.1, label="Temperature"),
33
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.05, label="Top-p"),
34
+ ],
35
+ title="🧠 CouncilShell Prototype",
36
+ description="Send a message and receive a streamed reply from the OSS 20B model — no login required.",
37
+ )
38
+
39
+ if __name__ == "__main__":
40
+ chatbot.launch()