ChatGPT를 이용한 간단한 Web App 만들기 (python, streamlit)

2023. 3. 14. 11:02·Python/Open Source
반응형

Python Streamlit을 통해서 간단한 ChatGPT Web App 만들어보기

우선, Streamlit 이란?

  • https://docs.streamlit.io/
  • streamlit는 주로 데이터 사이언스, 머신 러닝 등에서 사용되는 커스터 마이징 가능한 간단하고 쉽게 웹앱을 만들어주는 오픈 소스이다.

사용할 ChatGPT SDK, Reverse Engineered ChatGPT API

revChatGPT repo는 abandod or deprecated 되었습니다.
python OpenAI sdk 사용을 권장 합니다.
  • https://github.com/acheong08/ChatGPT

Python 패키지 설치

pip install revChatGPT
pip install streamlit

chatgpt_with_streamlit.py 생성 및 실행

  • streamlit run chatgpt_with_streamlit.py
import random

import streamlit
from streamlit.commands.page_config import RANDOM_EMOJIS

streamlit.set_page_config(page_title="Raynor ChatGPT", page_icon=random.choice(RANDOM_EMOJIS), menu_items={})
streamlit.title("Demo ChatGPT with Streamlit")
streamlit.sidebar.header("Chatting")
streamlit.sidebar.info("Chat")


def app_main():
    user_query = streamlit.text_input("Enter").strip()

app_main()
  • http://localhost:8501 접속

reversed ChatGPT SDK 연동

  • API 인증은 https://github.com/acheong08/ChatGPT 여러 가지 방법에 대해서 제시해주고 있다.
  • access_tokne 인증을 선택해서 진행, 현재 계정 Token 가져오기 https://chat.openai.com/api/auth/session
import logging
import random

import streamlit
from revChatGPT.V1 import Chatbot
from streamlit.commands.page_config import RANDOM_EMOJIS

streamlit.set_page_config(page_title="Raynor ChatGPT", page_icon=random.choice(RANDOM_EMOJIS), menu_items={})
streamlit.title("Demo ChatGPT with Streamlit")
streamlit.sidebar.header("Chatting")
streamlit.sidebar.info("Chat")

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
element = streamlit.empty()


# https://chat.openai.com/api/auth/session
def request_to_rev_openai(query):
    chatbot = Chatbot(config={
        "access_token": "token"
    })

    prev_text = ""
    for data in chatbot.ask(prompt=query):
        prev_text = data["message"]
        element.write(prev_text, unsafe_allow_html=True)

def app_main():
    user_query = streamlit.text_input("Enter").strip()
    if user_query is not None and user_query and user_query != "":
        request_to_rev_openai(user_query)


app_main()

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)
'Python/Open Source' 카테고리의 다른 글
  • [Locust] 2. Locust를 통한 언어와 프레임워크 별 테스트
  • [Locust] 1. Locust 부하 테스트 툴(load testing tool)
  • [Python] Colorful print
  • [Python 오픈소스] Diagrams
상쾌한기분
상쾌한기분
  • 상쾌한기분
    상쾌한기분
    상쾌한기분
  • 전체
    오늘
    어제
    • 분류 전체보기 (250)
      • Python (44)
        • Python (26)
        • Django (6)
        • Flask (4)
        • Open Source (6)
      • Kotlin & Java (5)
        • Spring (2)
        • 프로젝트 (1)
      • Go (11)
      • Database (24)
        • MySQL (21)
        • Redis (3)
      • Infrastructure (2)
        • CDC (4)
        • Kafka (5)
        • Prometheus (2)
        • Fluentd (11)
        • Docker (1)
        • Airflow (2)
        • VPN (2)
      • IT (25)
        • AI (9)
        • Langchain (8)
        • Web (18)
        • Git (8)
        • 리팩토링 (9)
        • Micro Service Architecture (8)
        • Clean Code (16)
        • Design Pattern (0)
        • 수학 (1)
        • 알고리즘 (14)
      • OS (14)
        • Centos (10)
        • Ubuntu (3)
        • Mac (1)
      • Search Engine (2)
        • ElasticSearch (1)
        • Lucene Solr (1)
      • PHP (2)
        • Laravel (1)
        • Codeigniter (1)
  • 블로그 메뉴

    • Github 방문
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    오블완
    CDC
    ollama
    Kafka
    python
    Golang
    fluentd
    performance
    파이썬
    Langchain
    http
    prompt
    go
    git
    Redis
    LLM
    티스토리챌린지
    백준
    docker
    MYSQL
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
상쾌한기분
ChatGPT를 이용한 간단한 Web App 만들기 (python, streamlit)
상단으로

티스토리툴바