File size: 1,571 Bytes
f9d084b
 
 
 
 
 
 
 
 
328191d
f9d084b
 
bcd81d0
 
f9d084b
 
 
bcd81d0
 
f9d084b
 
bcd81d0
 
f9d084b
 
 
bcd81d0
328191d
f9d084b
 
bcd81d0
f9d084b
 
 
 
 
 
 
 
 
 
689666c
 
 
 
 
 
f9d084b
689666c
 
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
from openai import OpenAI
import gradio
import os

client = OpenAI(
    # This is the default and can be omitted
    api_key=os.environ["OPENAI_API_KEY"],
)

def chat_with_gpt(prompt):
    response = client.chat.completions.create(
        model="gpt-4o",
        messages = [
        {
            "role": "system",
            "content": [
                {
                    "type": "text",
                    "text": "You are a helpful election assistant. Can you provide the information of what's on my ballot in a table format? [\"What's on my ballot\", \"Endorsements or race info\"]. For endorsement, use what I care about -- \ngun safety regulation-- to prioritize which candidate supports this value."
                }
            ]
        },
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": f"Can you give me ballot info for location in year?"
                }
            ]
        }
        ],
        temperature=0,
        max_tokens=256,
        top_p=1,
        frequency_penalty=0,
        presence_penalty=0
        )

    return response.choices[0].message.content.strip()

#if __name__ == "__main__":
#    while True:
#        user_input = input("You: ")
#        if user_input.lower() in ["quit", "exit", "bye"]:
#            break
#        response = chat_with_gpt(user_input)
        #print("Chatbot: ", response)
demo = gradio.Interface(fn=chat_with_gpt, inputs = "text", outputs = "text", title = "Your Voter Guide" )
demo. launch(share =True)