Spaces:
Sleeping
Sleeping
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) |