chatgpt / app.py
seawolf2357's picture
initial commit
c913f7d
raw
history blame contribute delete
No virus
812 Bytes
import gradio as gr
from openai import api_request
import openai
def openai_response(input_string):
response = api_request(
"engines/chatbot/run",
{
"text": input_string,
"engine": "chatgpt",
"temperature": 0.5,
"max_tokens": 100
},
headers={"Authorization": "Bearer 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"}
)
return response['choices'][0]['text']
# μ‚¬μš©μž μž…λ ₯을 λ°›μ•„μ„œ openai에 μš”μ²­
input_text = gr.inputs.Textbox(lines=3, label="λŒ€ν™” μž…λ ₯")
# openai의 응닡을 좜λ ₯ν•˜κΈ° μœ„ν•œ μΈν„°νŽ˜μ΄μŠ€
output_text = gr.outputs.Textbox(label="openAI λŒ€λ‹΅")
# openai_response ν•¨μˆ˜μ— μ‚¬μš©μžμ˜ μž…λ ₯을 전달
interaction = gr.Interaction(input_text, output_text, openai_response)
interaction.launch()