Pagn13 commited on
Commit
ccffefd
·
verified ·
1 Parent(s): b5629a8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -18
app.py CHANGED
@@ -1,8 +1,10 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
- tiiuae/"falcon-7b-instruct"
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
@@ -22,19 +24,38 @@ def respond(message, history, system_message, max_tokens, temperature, top_p):
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
 
3
 
4
+ # Load the model from Hugging Face Hub
5
+ client = InferenceClient(model="tiiuae/falcon-7b-instruct")
6
+
7
+ # Chat completion function
8
  def respond(message, history, system_message, max_tokens, temperature, top_p):
9
  messages = [{"role": "system", "content": system_message}]
10
  messages += history
 
24
  response += token
25
  yield response
26
  except Exception as e:
27
+ yield f"[Error] {e}"
28
+
29
+ # Gradio interface layout
30
+ with gr.Blocks() as demo:
31
+ gr.Markdown("### 🧠 Falcon-7B-Instruct Chat UI — Powered by Hugging Face")
32
+
33
+ with gr.Row():
34
+ system_message = gr.Textbox(value="You are a helpful assistant.", label="System Prompt", lines=2)
35
+
36
+ with gr.Row():
37
+ message = gr.Textbox(placeholder="Ask something…", label="Your Message", lines=2)
38
+
39
+ with gr.Row():
40
+ max_tokens = gr.Slider(minimum=64, maximum=1024, value=256, step=64, label="Max Tokens")
41
+ temperature = gr.Slider(minimum=0.1, maximum=1.0, value=0.7, step=0.1, label="Temperature")
42
+ top_p = gr.Slider(minimum=0.1, maximum=1.0, value=0.9, step=0.1, label="Top-p (nucleus sampling)")
43
+
44
+ chatbot = gr.Chatbot()
45
+ state = gr.State([])
46
+
47
+ submit = gr.Button("Send")
48
+
49
+ def handle_submit(user_message, history, system_message, max_tokens, temperature, top_p):
50
+ history = history + [[user_message, ""]]
51
+ for updated_response in respond(user_message, history[:-1], system_message, max_tokens, temperature, top_p):
52
+ history[-1][1] = updated_response
53
+ yield history, history
54
+
55
+ submit.click(
56
+ handle_submit,
57
+ inputs=[message, state, system_message, max_tokens, temperature, top_p],
58
+ outputs=[chatbot, state],
59
+ )
60
+
61
+ demo.launch()