My_Ai / app.py
Really-amin's picture
Update app.py
1ca069a verified
raw
history blame
1.25 kB
import streamlit as st
from transformers import pipeline
from streamlit.components.v1 import components
import json
# بارگذاری مدل هوش مصنوعی
@st.cache_resource
def load_model():
return pipeline("text-generation", model="openai-community/gpt2")
model = load_model()
# نمایش HTML
def load_html():
with open("index.html", "r", encoding="utf-8") as f:
return f.read()
# استریم‌لیت اپلیکیشن
def main():
st.set_page_config(page_title="دستیار هوش مصنوعی", layout="wide")
st.title("دستیار هوش مصنوعی")
# دریافت ورودی از HTML
html_code = load_html()
components.html(html_code, height=600, scrolling=True)
st.text("اطلاعات را از ورودی HTML دریافت می‌کنیم...")
# API برای دریافت پیام کاربر
if st.experimental_get_query_params().get("generate"):
request = st.experimental_get_query_params()["generate"]
message = json.loads(request).get("message")
if message:
response = model(message, max_length=100, num_return_sequences=1)
st.json({"response": response[0]["generated_text"]})
if __name__ == "__main__":
main()