Spaces:
Runtime error
Runtime error
File size: 1,187 Bytes
154be51 09ef165 0c931c9 bad8a0a 0c931c9 3e0e1b0 0c931c9 6b95da7 c829901 154be51 3e0e1b0 ce1e212 3e0e1b0 661084b 154be51 |
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 40 41 42 43 44 45 |
import os
import openai
import gradio as gr
#1: OpenAI Chat
def openai_chat(prompt):
completions = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
max_tokens=1024,
n=1,
temperature=0.5,
)
message = completions.choices[0].text
return message.strip()
#2: Gradio Interface Function
def chatbot(input, history=[]):
output = openai_chat(input)
history.append((input, output))
return history, history
title ='ChatGPT response'
description = "Ask Q and get ChatGPT response"
examples = [
["India is in which continent?"],
["Name the Indian cricket team's captain"],
["Who is the president of America"]
]
#3: Launch Interface
openai_chat_demo = gr.Interface(fn = chatbot,
inputs = ["text",'state'],
outputs = ["chatbot",'state'], title = title, description = description ,examples = examples)
#.launch(debug = True)
##################################
#2:
from content_only import GET_gpt_output
##############################
demo = gr.TabbedInterface([openai_chat_demo, GET_gpt_output ], ["ChatGPT","Contents ONLY"])
if __name__ == "__main__":
demo.launch() |