Introduction: AI Website Python (Windows 10 or More)

I made a project that uses AI and runs on a website for free. I made this project because I love coding, interested in AI, and I like to improve on my projects.

Supplies

  1. Your computer, duh...
  2. Ollama and Mu installed (which I'll show you how to)

Step 1: Install Ollama and Mu Editor (if You Haven't)

Ollama is a free (AI) that supports over 100 models. We're using gemma:2b created by Google and it's the fastest model. Mu Editor is a Python editor and it's a simple editor. Click here to download Ollama, click here to download Mu.

Step 2: Getting Ready

pip install gradio ollama webbrowser

Open Mu and press the REPL button. Wait until it says "In [1]:" then type this above. Go to Command Prompt app and say: "ollama pull gemma:2b".

Step 3: GradioWEB File

import gradio as gr


def greet(name):
return f"Hello, {name}!"


def run(function):
global demo
demo = gr.Interface(fn=function, inputs="text", outputs="text")


def execute():
demo.launch(server_port=8801, share=True) # ← This starts the app on port 8801

save this as gradioWEB.py

Step 4: Ollama File

# Write your code here :-)
import ollama
def ask(prompt):
response = ollama.chat(model="gemma:2b", messages=[
{"role": "user", "content": prompt}
])
return response['message']['content']
#while True:
#print(ask(input("es: ")))

save this as Ollama.py

Step 5: Main.py

# Write your code here :-)
import Ollama
import gradioWEB as gr
import webbrowser as w


def respond(userinput):
return Ollama.ask(userinput)
w.open("http://REPLACE_THIS_WITH_IP:8801/")
while True:
try:
gr.run(respond)
gr.execute()
except Exception:
pass

Save and run this code.

Step 6: Understand the Code

gradioWEB.py has gradio's functions, it makes it easier to use gradio. Ollama.py uses ollama AI Gemma:2b. Comment me if you have errors or more information about the code.

Step 7: Watch It Do!

you'll see userinput box and output. Type something in userinput and wait for result!