Athspi commited on
Commit
1dd4d6a
·
verified ·
1 Parent(s): 27dd1e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -40
app.py CHANGED
@@ -1,40 +1,20 @@
1
- import gradio as gr
2
- from onnxruntime_genai import ChatSession, GenerationConfig, ORTModel
3
-
4
- # Path to the downloaded ONNX model
5
- MODEL_DIR = "model/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4"
6
-
7
- # Load the model
8
- model = ORTModel(MODEL_DIR, execution_provider="cpu")
9
- session = ChatSession(model)
10
-
11
- # Chat function
12
- def chat_with_phi4(message, history):
13
- history = history or []
14
- for past_msg in history:
15
- session.history.append((past_msg[0], past_msg[1]))
16
-
17
- reply = session.chat(message, config=GenerationConfig(max_new_tokens=300))
18
- history.append((message, reply))
19
- return history, history
20
-
21
- # Hugging Face logo
22
- HF_LOGO = "https://huggingface.co/front/assets/huggingface_logo-noborder.svg"
23
-
24
- # Gradio interface
25
- with gr.Blocks() as demo:
26
- gr.Image(value=HF_LOGO, width=120, show_label=False, show_download_button=False)
27
- gr.Markdown("### Chat with Microsoft Phi-4 Mini Instruct (ONNX)")
28
-
29
- chatbot = gr.Chatbot()
30
- user_input = gr.Textbox(label="Your message")
31
- state = gr.State([])
32
-
33
- send_btn = gr.Button("Send")
34
- clear_btn = gr.Button("Clear")
35
-
36
- send_btn.click(chat_with_phi4, [user_input, state], [chatbot, state])
37
- user_input.submit(chat_with_phi4, [user_input, state], [chatbot, state])
38
- clear_btn.click(lambda: ([], []), outputs=[chatbot, state])
39
-
40
- demo.launch()
 
1
+ # Core Gradio UI library
2
+ gradio>=4.0.0,<5.0.0
3
+
4
+ # ONNX Runtime GenAI for inference (CPU version)
5
+ # Use --pre as it's often in pre-release
6
+ # NOTE: If targeting a GPU Space, change this to onnxruntime-genai-cuda
7
+ # and update EXECUTION_PROVIDER in app.py to "cuda"
8
+ onnxruntime-genai --pre
9
+
10
+ # Hugging Face Hub for downloading models/files
11
+ huggingface_hub>=0.20.0
12
+
13
+ # ONNX Runtime itself (will be installed as a dependency of onnxruntime-genai,
14
+ # but specifying can sometimes help resolve version conflicts if needed)
15
+ # onnxruntime>=1.17.0 # Generally not needed to list explicitly
16
+
17
+ # Git LFS is needed by huggingface_hub to download large model files.
18
+ # It needs to be installed on the Space environment, which is usually handled
19
+ # by the Hugging Face Spaces infrastructure if not using Docker.
20
+ # If you encounter download issues, ensure git-lfs is available.