Spaces:
Running
Running
File size: 1,250 Bytes
88b8225 8fbe768 7114231 1ca069a ecb9c1c 1ca069a 329231e 8fbe768 7114231 8fbe768 1ca069a 8fbe768 1ca069a 7114231 8fbe768 1ca069a ecb9c1c 88b8225 1ca069a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
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()
|