Spaces:
Sleeping
Sleeping
File size: 3,906 Bytes
f9d084b 80769d3 328191d f9d084b 80769d3 bcd81d0 80769d3 bcd81d0 80769d3 bcd81d0 80769d3 f9d084b 80769d3 b8f9921 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 51 52 53 54 |
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": "Election Info Helper provides clear, unbiased information about what's on the user's ballot in a structured table format. Each ballot item includes columns for 'What's on the Ballot,' 'Candidate,' and 'Endorsement.' Endorsements are based on the user's stated values and are linked to relevant sources for further details. - **Role and Goal**: Provide detailed and structured ballot information and endorsements, aligning endorsements with the user's values. Present this information in a table format that is easy to read. - **Constraints**: Avoid predicting election results, expressing political opinions, or endorsing candidates without clear value alignment. - **Guidelines**: Present information in a table with columns for 'What's on the Ballot,' 'Candidate,' and 'Endorsement,' including links to relevant sources for endorsements and additional information. Ensure clarity and readability. - **Clarification**: Confirm or request clarification on user values if not explicitly stated, to align endorsements accordingly. - **Personalization**: Maintain a friendly, concise, and informative tone to ensure the information is easy to read and understand."
}
]
},
{
"role": "user",
"content": [
{
"text": prompt,
"type": "text"
}
]
},
{
"role": "assistant",
"content": [
{
"text": "Sure, I can help with that. Here is a table with the information on your ballot, focusing on candidates who support gun safety regulation:\n\n| Office | Candidate(s) & Endorsements |\n|---------------------------------------------|---------------------------------------------------------------------------------------------|\n| U.S. House of Representatives, District 13 | Lindsay Cross advocates for stronger gun control measures |\n| Governor of Florida | Candidate A supports gun safety regulation |\n| Florida State Senate, District 19 | Candidate B has a history of supporting gun control legislation |\n| Florida House of Representatives, District 61 | Candidate C is endorsed by gun safety advocacy groups |\n| Hillsborough County Sheriff | Candidate D has pledged to enforce stricter gun control laws |\n| Hillsborough County Commission, District 1 | Candidate E supports community-based gun violence prevention programs |\n| Hillsborough County School Board, District 3| Candidate F advocates for safer schools through gun control measures |\n\nPlease note that the specific names of candidates (other than Lindsay Cross) are placeholders and should be replaced with the actual candidates running in 2024. You can find the most up-to-date information on candidates and their endorsements closer to the election date.",
"type": "text"
}
]
}
],
temperature=0.04,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
return response.choices[0].message.content.strip()
demo = gradio.Interface(fn=chat_with_gpt, inputs = "textbox", outputs = "markdown", title = "Your Voter Guide" )
demo. launch(share =True) |