veeps commited on
Commit
f9d084b
1 Parent(s): 5f3ef11

adding app.py file

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ import gradio
3
+ import os
4
+
5
+ client = OpenAI(
6
+ # This is the default and can be omitted
7
+ api_key=os.environ["OPENAI_API_KEY"],
8
+ )
9
+
10
+ def chat_with_gpt(prompt):
11
+ response = client.chat.completions.create(
12
+ model="gpt-4o",
13
+ messages=[
14
+ {
15
+ "role": "system",
16
+ "content": [
17
+ {
18
+ "type": "text",
19
+ "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. "
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ "role": "user",
25
+ "content": [
26
+ {
27
+ "type": "text",
28
+ "text": "Can you give me ballot info for tampa florida in 20224?"
29
+ }
30
+ ]
31
+ },
32
+ {
33
+ "role": "assistant",
34
+ "content": [
35
+ {
36
+ "type": "text",
37
+ "text": "Sure, I can help with that. Here is a table with the information on your ballot for Tampa, Florida in 2024, 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."
38
+ }
39
+ ]
40
+ },
41
+ {
42
+ "role": "user",
43
+ "content": [
44
+ {
45
+ "type": "text",
46
+ "text": "Can you give me ballot info for tampa florida in 20224?\n"
47
+ }
48
+ ]
49
+ },
50
+ {
51
+ "role": "assistant",
52
+ "content": [
53
+ {
54
+ "type": "text",
55
+ "text": "I believe you meant to ask for ballot information for Tampa, Florida in 2024. 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 14 | **Kathy Castor** (Incumbent) - Supports gun safety regulation |\n| Governor of Florida | **Nikki Fried** - Advocates for stronger gun control measures |\n| Florida State Senate, District 19 | **Janet Cruz** - Has a history of supporting gun control legislation |\n| Florida House of Representatives, District 61 | **Dianne Hart** - Endorsed by gun safety advocacy groups |\n| Hillsborough County Sheriff | **Chad Chronister** (Incumbent) - Supports certain gun control measures |\n| Hillsborough County Commission, District 1 | **Harry Cohen** - Supports community-based gun violence prevention programs |\n| Hillsborough County School Board, District 3| **Jessica Vaughn** - Advocates for safer schools through gun control measures |\n\nPlease verify the candidates and their positions closer to the election date, as endorsements"
56
+ }
57
+ ]
58
+ }
59
+ ],
60
+ temperature=0,
61
+ max_tokens=256,
62
+ top_p=1,
63
+ frequency_penalty=0,
64
+ presence_penalty=0
65
+ )
66
+
67
+ return response.choices[0].message.content.strip()
68
+
69
+ if __name__ == "__main__":
70
+ while True:
71
+ user_input = input("You: ")
72
+ if user_input.lower() in ["quit", "exit", "bye"]:
73
+ break
74
+ response = chat_with_gpt(user_input)
75
+ #print("Chatbot: ", response)
76
+ demo = gradio.Interface(fn=chat_with_gpt, inputs = "text", outputs = "text", title = "Your Voter Guide" )
77
+ demo. launch(share =True)