AI Website Python (Windows 10 or More)

by kved144 in Design > Websites

12 Views, 0 Favorites, 0 Comments

AI Website Python (Windows 10 or More)

gradioOllama.png

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

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

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

dollama.png
mud.png

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.

Getting Ready

dopip.png
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".

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

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

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.

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.

Watch It Do!

gradioOllama.png

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