|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
|
|
|
|
|
|
jarvis = pipeline("text2text-generation", model="google/flan-t5-small") |
|
|
|
|
|
|
|
|
def chat(message, history): |
|
|
|
|
|
context = "" |
|
|
for h in history: |
|
|
context += f"User: {h['content']}\nJarvis: {h.get('response', '')}\n" |
|
|
context += f"User: {message}\nJarvis:" |
|
|
|
|
|
|
|
|
response = jarvis(context, max_new_tokens=128, temperature=0.7, do_sample=True) |
|
|
reply = response[0]["generated_text"] |
|
|
|
|
|
|
|
|
history.append({"role": "user", "content": message}) |
|
|
history.append({"role": "assistant", "content": reply}) |
|
|
return "", history |
|
|
|
|
|
|
|
|
gr.ChatInterface( |
|
|
fn=chat, |
|
|
title="Jarvis AI V2", |
|
|
description="Your personal AI assistant β accessible anywhere in the world.", |
|
|
theme="soft", |
|
|
type="messages", |
|
|
).launch(share=True) |
|
|
|