Spaces:
Runtime error
Runtime error
File size: 2,109 Bytes
4db43a4 028139c 4db43a4 3033903 4db43a4 3033903 4db43a4 3033903 4db43a4 c2cb504 ed6061c 4db43a4 98a941b 3033903 4db43a4 3033903 4db43a4 98a941b 4db43a4 | 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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | from email import message
import gradio as gr
import os
import openai
from create_poll import create_poll
from utils import GPTCompletion
from dotenv import load_dotenv
gr.close_all()
load_dotenv()
openai.api_key = os.environ["OPENAI_API_KEY"]
def chatWithGPT(chatHistory):
completion = GPTCompletion(system="You are an AI chatting with a human.", max_tokens=2048, temperature=1.5)
gptResponse = completion.chatComplete(chatHistory)
chatHistory[-1][1] = gptResponse
return chatHistory
with gr.Blocks() as demo:
chatHistory = gr.State(value = [])
def generateResponse(message, chatHistory):
completion = GPTCompletion(system="You are an AI chatting with a human.", max_tokens=2048, temperature=1.5)
gptResponse = completion.chatComplete(chatHistory,message)
chatHistory.append((message, gptResponse))
return chatHistory
def pollinize(chatHistory):
chatList = []
for log in chatHistory:
chatList.append("User: " + log[0])
chatList.append("AI: " + log[1])
chatString = "\n".join(chatList)
return create_poll(chatString, openai.api_key)
def uploadApi(apikey):
openai.api_key = apikey
gr.Markdown("This little app is a demonstration of how LLMs can be used to create Polls from a chat. To give it a try, discuss a topic with ChatGPT first and then push Generate Poll button. Poll question will be generated on the context of the chat.")
chatbot = gr.Chatbot().style(height=460)
input = gr.Textbox(label="Messeage")
nextBtn = gr.Button("Send message")
nextBtn.click(generateResponse, [input, chatHistory], chatbot, scroll_to_output=True, show_progress=True)
debatePoll = gr.Textbox(label="Poll")
pollinizeButton = gr.Button("Create a poll")
pollinizeButton.click(pollinize,chatHistory, debatePoll, scroll_to_output=True, show_progress=True)
apikey = gr.Textbox(label="API Key")
apiUpload = gr.Button("Upload custom api key")
apiUpload.click(uploadApi, apikey, None, scroll_to_output=True, show_progress=True)
demo.launch() |