{"id":27270166,"url":"https://github.com/chrnthnkmutt/slm-py-experiment","last_synced_at":"2025-07-14T08:13:22.903Z","repository":{"id":238628474,"uuid":"796983570","full_name":"chrnthnkmutt/slm-py-experiment","owner":"chrnthnkmutt","description":"This repository is used for making demonstration of running Phi-3, Microsoft's Small Language Model, locally on the device by using ollama, along with Python library, Streamlit. With the use case of Phi-3 vision.","archived":false,"fork":false,"pushed_at":"2025-06-07T06:07:26.000Z","size":16058,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-07T07:18:57.041Z","etag":null,"topics":["ollama","phi3","phi3-vision","python","streamlit"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chrnthnkmutt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-05-07T01:33:35.000Z","updated_at":"2025-06-07T06:07:29.000Z","dependencies_parsed_at":"2025-04-11T12:04:43.221Z","dependency_job_id":"3cc70545-1c0a-494b-9728-51b53c220b0c","html_url":"https://github.com/chrnthnkmutt/slm-py-experiment","commit_stats":null,"previous_names":["chrnthnkmutt/phi3_experiment","chrnthnkmutt/phi3-py-experiment","chrnthnkmutt/slm-py-experiment"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/chrnthnkmutt/slm-py-experiment","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnthnkmutt%2Fslm-py-experiment","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnthnkmutt%2Fslm-py-experiment/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnthnkmutt%2Fslm-py-experiment/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnthnkmutt%2Fslm-py-experiment/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chrnthnkmutt","download_url":"https://codeload.github.com/chrnthnkmutt/slm-py-experiment/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chrnthnkmutt%2Fslm-py-experiment/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265262556,"owners_count":23736413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ollama","phi3","phi3-vision","python","streamlit"],"created_at":"2025-04-11T12:04:31.544Z","updated_at":"2025-07-14T08:13:22.864Z","avatar_url":"https://github.com/chrnthnkmutt.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# phi3-py-experiment\n## Intelligent Chatbot with Phi-3 SLM and Streamlit Library\n\n![](Project_Banner.jpg)\n\nLet's build a chatbot with just Python using the Streamlit library, Ollama, and Microsoft Phi-3. \n\n### Streamlit: \nturns data scripts into shareable web apps in minutes. All in pure Python. No front‑end experience required.\nYou can find more info in the official Streamlit docs.\n\n\n### Ollama: \nallows you to run open-source large language models, locally\nYou can find more info in the official Ollama docs. \n\n\n### Phi-3 Mini: \nis a 3.8B parameters, lightweight, state-of-the-art open model by Microsoft.\nYou can find more info in the official Phi-3 Mini docs.\n\n\n### Steps\n\n*If you can't use `pip` then use `conda` instead to install the library*. Ensure that you have install Ollama platform in to your computer, by visiting this link: [Ollama.com](https://ollama.com/)\n\n1 - Create a new conda environment\n```\nconda create --name envStreamPhi\n```\n2 - Activate the environment\n```\nconda activate envStreamPhi\n```\n3 - Clone StreamLit template\n```\ngit clone https://github.com/streamlit/streamlit.git\nconda install streamlit\n```\n4 - Install ollama \u0026 pull the phi-3 model\n```\npip install ollama\nollama pull phi3\n```\n5 - Pull the Embeddings model:\n```\nollama pull nomic-embed-text\n```\n6 - Test installation\n```\nstreamlit hello\n```\n\n### Build the AI assistant\n\nIn order to build the AI assistant, you have 2 choices : clone the repo and get all the code from the get-go or coding along with me.\n\n#### I - First option : \n1 - Clone the project from Github \n```\ngit clone https://github.com/chrnthnkmutt/phi3_experiment.git\n```\n2 - run the application\n```\nstreamlit run app.py\n```\n\n#### II - Second option: \ncode along\n1 - Create your app.py file\n```\napp.py\n```\n2 - Add imports\n```py\nimport streamlit as st\nimport ollama\n```\n\n3 - Add the defacto message\n```py\nif \"messages\" not in st.session_state:\n    st.session_state[\"messages\"] = [{\"role\": \"assistant\", \"content\": \"Hello tehre, how can I help you, today?\"}]\n```\n4 - Add the message history\n```py\nfor msg in st.session_state.messages:\n    if msg[\"role\"] == \"user\":\n        st.chat_message(msg[\"role\"], avatar=\"🧑‍💻\").write(msg[\"content\"])\n    else:\n        st.chat_message(msg[\"role\"], avatar=\"🤖\").write(msg[\"content\"])\n```\n5 - Configure model\n```py\ndef generate_response():\n    response = ollama.chat(model='phi3', stream=True, messages=st.session_state.messages)\n    for partial_resp in response:\n        token = partial_resp[\"message\"][\"content\"]\n        st.session_state[\"full_message\"] += token\n        yield token\n```\n6 - Configure the prompt\n```py\nif prompt := st.chat_input():\n    st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n    st.chat_message(\"user\", avatar=\"🧑‍💻\").write(prompt)\n    st.session_state[\"full_message\"] = \"\"\n    st.chat_message(\"assistant\", avatar=\"🤖\").write_stream(generate_response)\n    st.session_state.messages.append({\"role\": \"assistant\", \"content\": st.session_state[\"full_message\"]})   \n```\n7 - all the codebase of app.py\n```py\nimport streamlit as st\nimport ollama\n\nst.title(\"💬 Phi3 Chatbot\")\n\nif \"messages\" not in st.session_state:\n    st.session_state[\"messages\"] = [{\"role\": \"assistant\", \"content\": \"Hello tehre, how can I help you, today?\"}]\n\n### Write Message History\nfor msg in st.session_state.messages:\n    if msg[\"role\"] == \"user\":\n        st.chat_message(msg[\"role\"], avatar=\"🧑‍💻\").write(msg[\"content\"])\n    else:\n        st.chat_message(msg[\"role\"], avatar=\"🤖\").write(msg[\"content\"])\n\n## Configure the model\ndef generate_response():\n    response = ollama.chat(model='phi3', stream=True, messages=st.session_state.messages)\n    for partial_resp in response:\n        token = partial_resp[\"message\"][\"content\"]\n        st.session_state[\"full_message\"] += token\n        yield token\n\nif prompt := st.chat_input():\n    st.session_state.messages.append({\"role\": \"user\", \"content\": prompt})\n    st.chat_message(\"user\", avatar=\"🧑‍💻\").write(prompt)\n    st.session_state[\"full_message\"] = \"\"\n    st.chat_message(\"assistant\", avatar=\"🤖\").write_stream(generate_response)\n    st.session_state.messages.append({\"role\": \"assistant\", \"content\": st.session_state[\"full_message\"]})   \n```\nRun the Streamlit app \n```\nstreamlit run app.py\n```\n## Experimenting Phi-3 Vision on Jupyter Notebook\n\nVisit the file name `phi3-vis-ocr.ipynb` and `phi3-vis-gen.ipynb` for execution the file for testing multimodal performance of Phi-3 Vision. Recommended to run on Google Collaboratory\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrnthnkmutt%2Fslm-py-experiment","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchrnthnkmutt%2Fslm-py-experiment","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchrnthnkmutt%2Fslm-py-experiment/lists"}