
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
import gradio as gr
import openai
import os
from langchain_openai import ChatOpenAI
from langchain_core.prompts import (
ChatPromptTemplate,
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
)
openai.api_key = "sk-msVzLA4rcJJP1LV8EDVCXIEkahzDcPXvmqwzmbh3SFT3BlbkFJ6isMCKPonm2cm2ddpcRYVfTgfS3tMxWLnkcNn6kJUA"
os.environ["OPENAI_API_KEY"]=openai.api_key # typo fixed: changed OPEN_API_KEY to OPENAI_API_KEY
client = openai.OpenAI()
def translate_text(text):
chat = ChatOpenAI(temperature=0)
template="You are a helpful assistant that translates {input_language} to {output_language}."
system_message_prompt = SystemMessagePromptTemplate.from_template(template)
human_template="{text}"
human_message_prompt = HumanMessagePromptTemplate.from_template(human_template)
chat_prompt = ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])
response = chat(
chat_prompt.format_prompt(
input_language="korean", output_language="english", text=text
).to_messages()
)
return response.content
def generate_response(prompt, size):
translated_prompt = translate_text(prompt)
gpt_prompt = [
{"role": "system", "content": "imagine the details of the input's appearence. please respond breifly"},
{"role": "user", "content": translated_prompt}
]
gpt_response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=gpt_prompt,
)
gpt_prompt_result = gpt_response.choices[0].message.content
dalle_response = client.images.generate(
model="dall-e-3",
prompt=f"A giant gorilla peacefully observing the city from the top of a skyscraper", # Changed prompt
# prompt=gpt_prompt_result,
size=size,
quality="standard",
n=1,
style="natural",
)
image_url = dalle_response.data[0].url
return gpt_prompt_result, image_url
image_sizes = gr.Dropdown(choices=["1024x1024", "1024x1792","1792x1024"], label="이미지 크기")
iface = gr.Interface(
fn=generate_response,
inputs=["text", image_sizes],
outputs=["text", "image"],
title="나만의 Dall-E 봇",
description="사용자의 프로프트를 기반으로 ChatGPT와 DALL-E를 사용하여 이미지를 제작합니다."
)
iface.launch(debug=True, share=True)
이를 실행하면
Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().
IMPORTANT: You are using gradio version 4.0.2, however version 4.29.0 is available, please upgrade.
--------
Running on public URL: https://b4d30d51877dd4f18a.gradio.live
This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)
이렇게 메시지가 뜹니다.
어떻게 대처하지요?
