Spaces:
Sleeping
Sleeping
Force update for app.py
Browse files- .gradio/certificate.pem +31 -0
- app.py +61 -36
.gradio/certificate.pem
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
-----BEGIN CERTIFICATE-----
|
| 2 |
+
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
|
| 3 |
+
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
|
| 4 |
+
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
|
| 5 |
+
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
|
| 6 |
+
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
|
| 7 |
+
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
|
| 8 |
+
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
|
| 9 |
+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
|
| 10 |
+
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
|
| 11 |
+
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNK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8NwdC
|
| 26 |
+
jNPElpzVmbUq4JUagEiuTDkHzsxHpFKVK7q4+63SM1N95R1NbdWhscdCb+ZAJzVc
|
| 27 |
+
oyi3B43njTOQ5yOf+1CceWxG1bQVs5ZufpsMljq4Ui0/1lvh+wjChP4kqKOJ2qxq
|
| 28 |
+
4RgqsahDYVvTH9w7jXbyLeiNdd8XM2w9U/t7y0Ff/9yi0GE44Za4rF2LN9d11TPA
|
| 29 |
+
mRGunUHBcnWEvgJBQl9nJEiU0Zsnvgc/ubhPgXRR4Xq37Z0j4r7g1SgEEzwxA57d
|
| 30 |
+
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
|
| 31 |
+
-----END CERTIFICATE-----
|
app.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
|
|
|
| 4 |
|
| 5 |
# Load API key from environment variable
|
| 6 |
API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
|
@@ -50,9 +51,23 @@ def get_ai_reasoning_and_response(system_prompt, question):
|
|
| 50 |
# Get questions
|
| 51 |
def get_random_question():
|
| 52 |
return get_ai_response(
|
| 53 |
-
"Generate
|
| 54 |
"Provide one question only, no numbering."
|
| 55 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
#-----
|
| 57 |
|
| 58 |
|
|
@@ -68,13 +83,13 @@ def start_game():
|
|
| 68 |
transcript.append(q1)
|
| 69 |
|
| 70 |
# Return joined transcript + pass it as our running state
|
| 71 |
-
return "\n".join(transcript), transcript
|
| 72 |
|
| 73 |
-
def submit_q1(user_ans_q1, transcript):
|
| 74 |
-
#
|
| 75 |
-
ai1 =
|
| 76 |
-
ai2 =
|
| 77 |
-
ai3 =
|
| 78 |
|
| 79 |
# Append user’s answer
|
| 80 |
transcript.append(f"Participant 4 (You): {user_ans_q1}")
|
|
@@ -85,16 +100,16 @@ def submit_q1(user_ans_q1, transcript):
|
|
| 85 |
transcript.append("") # blank line for readability
|
| 86 |
|
| 87 |
# Present second question
|
| 88 |
-
q2 = "Question 2:
|
| 89 |
transcript.append(q2)
|
| 90 |
|
| 91 |
-
return "\n".join(transcript), transcript
|
| 92 |
|
| 93 |
-
def submit_q2(user_ans_q2, transcript):
|
| 94 |
# Hardcoded AI answers for demonstration
|
| 95 |
-
ai1 =
|
| 96 |
-
ai2 =
|
| 97 |
-
ai3 =
|
| 98 |
|
| 99 |
# Append user’s answer
|
| 100 |
transcript.append(f"Participant 4 (You): {user_ans_q2}")
|
|
@@ -114,11 +129,25 @@ def cast_vote(user_vote, transcript):
|
|
| 114 |
# Example voting logic
|
| 115 |
votes = {1: 0, 2: 0, 3: 0, 4: 0}
|
| 116 |
|
| 117 |
-
#
|
| 118 |
-
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
# User’s vote
|
| 121 |
-
votes[user_vote] += 1
|
| 122 |
|
| 123 |
transcript.append(f"\nYou voted for Participant {user_vote}")
|
| 124 |
transcript.append("\n=== Final Results ===")
|
|
@@ -133,32 +162,31 @@ def cast_vote(user_vote, transcript):
|
|
| 133 |
return "\n".join(transcript), transcript
|
| 134 |
|
| 135 |
with gr.Blocks() as demo:
|
| 136 |
-
# State to store
|
| 137 |
-
|
|
|
|
|
|
|
| 138 |
|
| 139 |
gr.Markdown("# Who's the Human?\nA simple multi-step Gradio demo.")
|
| 140 |
|
| 141 |
-
# This text area displays the unfolding transcript
|
| 142 |
transcript_box = gr.Textbox(
|
| 143 |
label="Game Transcript",
|
| 144 |
lines=15,
|
| 145 |
interactive=False
|
| 146 |
)
|
| 147 |
|
| 148 |
-
# Button to start the game
|
| 149 |
start_btn = gr.Button("Start Game")
|
| 150 |
start_btn.click(
|
| 151 |
start_game,
|
| 152 |
-
outputs=[transcript_box,
|
| 153 |
)
|
| 154 |
|
| 155 |
-
# Q1 input and button
|
| 156 |
user_q1 = gr.Textbox(label="Your answer for Q1:")
|
| 157 |
submit_q1_btn = gr.Button("Submit Q1")
|
| 158 |
submit_q1_btn.click(
|
| 159 |
submit_q1,
|
| 160 |
-
inputs=[user_q1,
|
| 161 |
-
outputs=[transcript_box,
|
| 162 |
)
|
| 163 |
|
| 164 |
# Q2 input and button
|
|
@@ -166,23 +194,20 @@ with gr.Blocks() as demo:
|
|
| 166 |
submit_q2_btn = gr.Button("Submit Q2")
|
| 167 |
submit_q2_btn.click(
|
| 168 |
submit_q2,
|
| 169 |
-
inputs=[user_q2,
|
| 170 |
-
outputs=[transcript_box,
|
| 171 |
)
|
| 172 |
|
| 173 |
-
# Voting
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
step=1,
|
| 178 |
-
value=1,
|
| 179 |
label="Who do YOU think is human? (1-4)"
|
| 180 |
)
|
| 181 |
vote_btn = gr.Button("Cast Vote")
|
| 182 |
vote_btn.click(
|
| 183 |
cast_vote,
|
| 184 |
-
inputs=[
|
| 185 |
-
outputs=[transcript_box,
|
| 186 |
)
|
| 187 |
-
|
| 188 |
demo.launch(debug=True, share=True)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
+
import random
|
| 5 |
|
| 6 |
# Load API key from environment variable
|
| 7 |
API_KEY = os.getenv("DEEPSEEK_API_KEY")
|
|
|
|
| 51 |
# Get questions
|
| 52 |
def get_random_question():
|
| 53 |
return get_ai_response(
|
| 54 |
+
"Generate five unique and creative general knowledge questions suitable for a trivia game (that a 10 year old can answer). Each question should cover a different category, such as geography, history, science, entertainment, and sports. Ensure the questions vary in difficulty and format. Then, randomly select one of the five questions to return as the final output.",
|
| 55 |
"Provide one question only, no numbering."
|
| 56 |
)
|
| 57 |
+
|
| 58 |
+
# Get questions 2
|
| 59 |
+
def get_random_question2():
|
| 60 |
+
return get_ai_response(
|
| 61 |
+
"Generate five unique and creative general knowledge questions suitable for a trivia game (that a 10 year old can answer). Each question should cover a different category history, science, entertainment, and sports. Ensure the questions vary in difficulty and format. Then, randomly select one of the five questions to return as the final output.",
|
| 62 |
+
"Provide one question only, no numbering."
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
# AI answer
|
| 66 |
+
def ai_answer(question):
|
| 67 |
+
return get_ai_response(
|
| 68 |
+
"Answer this question naturally and concisely like a human, 5-8 words max:",
|
| 69 |
+
question
|
| 70 |
+
)
|
| 71 |
#-----
|
| 72 |
|
| 73 |
|
|
|
|
| 83 |
transcript.append(q1)
|
| 84 |
|
| 85 |
# Return joined transcript + pass it as our running state
|
| 86 |
+
return "\n".join(transcript), transcript, q1
|
| 87 |
|
| 88 |
+
def submit_q1(user_ans_q1, transcript, q1):
|
| 89 |
+
# Generated AI answers
|
| 90 |
+
ai1 = ai_answer(q1)
|
| 91 |
+
ai2 = ai_answer(q1)
|
| 92 |
+
ai3 = ai_answer(q1)
|
| 93 |
|
| 94 |
# Append user’s answer
|
| 95 |
transcript.append(f"Participant 4 (You): {user_ans_q1}")
|
|
|
|
| 100 |
transcript.append("") # blank line for readability
|
| 101 |
|
| 102 |
# Present second question
|
| 103 |
+
q2 = f"Question 2: {get_random_question2()}"
|
| 104 |
transcript.append(q2)
|
| 105 |
|
| 106 |
+
return "\n".join(transcript), transcript, q2
|
| 107 |
|
| 108 |
+
def submit_q2(user_ans_q2, transcript, q2):
|
| 109 |
# Hardcoded AI answers for demonstration
|
| 110 |
+
ai1 = ai_answer(q2)
|
| 111 |
+
ai2 = ai_answer(q2)
|
| 112 |
+
ai3 = ai_answer(q2)
|
| 113 |
|
| 114 |
# Append user’s answer
|
| 115 |
transcript.append(f"Participant 4 (You): {user_ans_q2}")
|
|
|
|
| 129 |
# Example voting logic
|
| 130 |
votes = {1: 0, 2: 0, 3: 0, 4: 0}
|
| 131 |
|
| 132 |
+
# Get AI votes dynamically
|
| 133 |
+
for i in range(1, 4): # Three AI participants
|
| 134 |
+
ai_vote = int(get_ai_response(
|
| 135 |
+
"You are an AI participant in a game with 4 Participants. "
|
| 136 |
+
f"You are participant No {i}. One of the participants is a human, and the rest are AIs.\n"
|
| 137 |
+
f"Based on the last responses:\n'{transcript}'\n"
|
| 138 |
+
"Who do you think is the human? Respond with only the number (1-4), but DO NOT vote for yourself.",
|
| 139 |
+
"Who do you vote for?"
|
| 140 |
+
))
|
| 141 |
+
|
| 142 |
+
# Ensure the AI does not vote for itself
|
| 143 |
+
if ai_vote in votes and ai_vote != i:
|
| 144 |
+
votes[ai_vote] += 1
|
| 145 |
+
else:
|
| 146 |
+
print(f"Invalid AI vote detected: {ai_vote}, defaulting to random (excluding {i}).")
|
| 147 |
+
valid_choices = [x for x in [1, 2, 3, 4] if x != i] # Exclude AI's own number
|
| 148 |
+
votes[random.choice(valid_choices)] += 1 # Prevent crash
|
| 149 |
# User’s vote
|
| 150 |
+
votes[int(user_vote)] += 1
|
| 151 |
|
| 152 |
transcript.append(f"\nYou voted for Participant {user_vote}")
|
| 153 |
transcript.append("\n=== Final Results ===")
|
|
|
|
| 162 |
return "\n".join(transcript), transcript
|
| 163 |
|
| 164 |
with gr.Blocks() as demo:
|
| 165 |
+
# State to store transcript and questions
|
| 166 |
+
transcript_state = gr.State([])
|
| 167 |
+
current_q1_state = gr.State("")
|
| 168 |
+
current_q2_state = gr.State("") # New state for Q2
|
| 169 |
|
| 170 |
gr.Markdown("# Who's the Human?\nA simple multi-step Gradio demo.")
|
| 171 |
|
|
|
|
| 172 |
transcript_box = gr.Textbox(
|
| 173 |
label="Game Transcript",
|
| 174 |
lines=15,
|
| 175 |
interactive=False
|
| 176 |
)
|
| 177 |
|
|
|
|
| 178 |
start_btn = gr.Button("Start Game")
|
| 179 |
start_btn.click(
|
| 180 |
start_game,
|
| 181 |
+
outputs=[transcript_box, transcript_state, current_q1_state]
|
| 182 |
)
|
| 183 |
|
|
|
|
| 184 |
user_q1 = gr.Textbox(label="Your answer for Q1:")
|
| 185 |
submit_q1_btn = gr.Button("Submit Q1")
|
| 186 |
submit_q1_btn.click(
|
| 187 |
submit_q1,
|
| 188 |
+
inputs=[user_q1, transcript_state, current_q1_state],
|
| 189 |
+
outputs=[transcript_box, transcript_state, current_q2_state] # Output Q2 to state
|
| 190 |
)
|
| 191 |
|
| 192 |
# Q2 input and button
|
|
|
|
| 194 |
submit_q2_btn = gr.Button("Submit Q2")
|
| 195 |
submit_q2_btn.click(
|
| 196 |
submit_q2,
|
| 197 |
+
inputs=[user_q2, transcript_state, current_q2_state], # Add Q2 state input
|
| 198 |
+
outputs=[transcript_box, transcript_state]
|
| 199 |
)
|
| 200 |
|
| 201 |
+
# Voting radio + button
|
| 202 |
+
vote_radio = gr.Radio(
|
| 203 |
+
choices=['1', '2', '3', '4'],
|
| 204 |
+
value='1',
|
|
|
|
|
|
|
| 205 |
label="Who do YOU think is human? (1-4)"
|
| 206 |
)
|
| 207 |
vote_btn = gr.Button("Cast Vote")
|
| 208 |
vote_btn.click(
|
| 209 |
cast_vote,
|
| 210 |
+
inputs=[vote_radio, transcript_state],
|
| 211 |
+
outputs=[transcript_box, transcript_state]
|
| 212 |
)
|
|
|
|
| 213 |
demo.launch(debug=True, share=True)
|