File size: 2,158 Bytes
b2a8fde
 
78e2d06
 
 
b2a8fde
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78e2d06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2a8fde
78e2d06
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
import os
import io
import openai
import gradio as gr

import IPython.display
from PIL import Image

import base64 
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv()) # read local .env file
hf_api_key ='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'

import requests

def query(payload):
	response = requests.post(API_URL, headers=headers, json=payload)
	return response.content

# Helper function
import requests, json

openai.api_key = "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"  

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='gpt-3.5-turbo',
        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="PeachTalk+",
                description="An AI Powered Chatbot with Computer Vision and Image Generation Capabilities Currently Under Development By Peach State Innovation and Technology. Ask Me About Question About Anything...From Georgia and Beyond...And I'll Give You An Answer!",
                theme= gr.themes.Glass(primary_hue="amber", neutral_hue="lime"),
                retry_btn=None,
                clear_btn="Clear")

A2 = gr.load(
             "huggingface/google/vit-base-patch16-224",
              title="Upon Further Review - AI Vision and Identity Technology",
              theme= gr.themes.Glass(primary_hue="amber", neutral_hue="lime"))

A3 = gr.load("huggingface/google/vit-base-patch16-224")

pcp = gr.TabbedInterface([A1, A2], ["Chat", "Describe", "Create"], theme= gr.themes.Glass(primary_hue="amber", neutral_hue="lime"))
pcp.queue().launch()