Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import os | |
import openai | |
import gradio as gr | |
openai.api_key = os.getenv('OPEN_AI_KEY') | |
hf_t_key = ('HF_TOKEN_KEY') | |
def predict(message, history): | |
history_openai_format = [] | |
for human, assistant in history: | |
history_openai_format.append({"role": "user", "content": human }) | |
history_openai_format.append({"role": "assistant", "content": assistant}) | |
history_openai_format.append({"role": "user", "content": message}) | |
response = openai.ChatCompletion.create( | |
model='ft:gpt-3.5-turbo-1106:2292030-peach-tech::8cxzbHH4', | |
messages= history_openai_format, | |
temperature=1.0, | |
stream=True | |
) | |
partial_message = "" | |
for chunk in response: | |
if len(chunk['choices'][0]['delta']) != 0: | |
partial_message = partial_message + chunk['choices'][0]['delta']['content'] | |
yield partial_message | |
A1 = gr.ChatInterface(predict, | |
title="COLLEAGUE", | |
description="An AI Productivity Assistant with Chat, Vision, and Image Generation Capabilities, Built By Peach State Innovation and Technology. Select The Corresponding Tab For Tool Accessibility", | |
textbox=gr.Textbox(placeholder="Enter your question/prompt here..."), | |
theme= gr.themes.Glass(primary_hue="neutral", neutral_hue="slate"), | |
retry_btn=None, | |
clear_btn="Clear Conversation") | |
A2 = gr.load( | |
"models/Salesforce/blip-image-captioning-large", | |
title=" ", | |
description="Take and Upload a Photo or Existing Image, I'll Give You Its Description", | |
outputs=[gr.Textbox(label="I see...")], | |
theme= gr.themes.Glass(primary_hue="neutral", neutral_hue="slate")) | |
A3 = gr.load( | |
"models/stabilityai/stable-diffusion-xl-base-1.0", | |
inputs=[gr.Textbox(label="Enter Your Image Description")], | |
outputs=[gr.Image(label="Image")], | |
title=" ", | |
description="Bring Your Imagination Into Existence On The Digital Canvas With COLLEAGUE, Powered With Stable Diffusion", | |
allow_flagging="never", | |
examples=["A monster wandering the streets of downtown Atlanta","A robot eating pizza in a Brazilian favela"]) | |
pcp = gr.TabbedInterface([A1, A2, A3], ["Chat", "Describe", "Create"], theme= gr.themes.Glass(primary_hue="neutral", neutral_hue="slate")) | |
pcp.queue().launch() |