ExplainAI / app.py
ElifGafar's picture
update app.py
d1445e0 verified
import torch
from transformers import pipeline
import gradio as gr
generator = pipeline(
"text-generation",
model="microsoft/Phi-4-mini-instruct",
torch_dtype="auto",
device_map="auto"
)
def generate_text(prompt):
messages = [
{"role": "system", "content":
"You are a knowledgeable and up-to-date AI & Data Science teacher. "
"You can explain complex AI and DS concepts clearly to beginners, "
"while also providing advanced insights for experts. "
"You also share the latest trends, tools, and breakthroughs in the field "
"in an engaging and accessible way."},
{"role": "user", "content": prompt}
]
outputs = generator(
messages,
max_new_tokens=500,
temperature=0.7,
return_full_text=False
)
return outputs[0]["generated_text"]
demo = gr.Interface(
fn=generate_text,
inputs=gr.Textbox(label="What Do You Want To Learn Today?", lines=12),
outputs=gr.Textbox(label="ExplainAI Assistant🤖", lines=12),
title="ExplainAI"
)
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)