Spaces:
Runtime error
Runtime error
Commit
·
4395b89
1
Parent(s):
6ccefab
Update app.py
Browse files
app.py
CHANGED
@@ -1,99 +1,42 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import random
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
return
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
return ''.join(decrypted_password)
|
34 |
-
|
35 |
-
def password_generator(password_length):
|
36 |
-
password = generate_password(password_length)
|
37 |
-
key = generate_password(password_length)
|
38 |
-
encrypted_password = encrypt_password(password, key)
|
39 |
-
return {'password': password, 'key': key, 'encrypted_password': encrypted_password}
|
40 |
-
|
41 |
-
def password_strength(password):
|
42 |
-
return {'password_strength': get_password_strength(password)}
|
43 |
-
|
44 |
-
def password_decrypt(encrypted_password, key):
|
45 |
-
password = decrypt_password(encrypted_password, key)
|
46 |
-
return {'password': password}
|
47 |
-
|
48 |
-
input_password_length = gr.inputs.Slider(minimum=4, maximum=32, step=1, default=12, label='Password Length')
|
49 |
-
input_password = gr.inputs.Textbox(label='Password')
|
50 |
-
input_encrypted_password = gr.inputs.Textbox(label='Encrypted Password')
|
51 |
-
input_key = gr.inputs.Textbox(label='Key')
|
52 |
-
|
53 |
-
output_generated_password = gr.outputs.Textbox(label='Generated Password')
|
54 |
-
output_generated_key = gr.outputs.Textbox(label='Generated Key')
|
55 |
-
output_encrypted_password = gr.outputs.Textbox(label='Encrypted Password')
|
56 |
-
output_password_strength = gr.outputs.Label(label='Password Strength')
|
57 |
-
output_decrypted_password = gr.outputs.Textbox(label='Decrypted Password')
|
58 |
-
|
59 |
-
interface = gr.Interface(
|
60 |
-
[
|
61 |
-
input_password_length,
|
62 |
-
input_password,
|
63 |
-
input_encrypted_password,
|
64 |
-
input_key,
|
65 |
-
gr.inputs.Button(label='Generate Password'),
|
66 |
-
gr.inputs.Button(label='Check Password Strength'),
|
67 |
-
gr.inputs.Button(label='Decrypt Password'),
|
68 |
],
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
output_password_strength,
|
74 |
-
output_decrypted_password,
|
75 |
-
],
|
76 |
-
title='Password Generator and Encryption/Decryption System',
|
77 |
)
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
return [result['password'], result['key'], result['encrypted_password'], None, None]
|
82 |
-
|
83 |
-
def password_strength_callback(password):
|
84 |
-
result = password_strength(password)
|
85 |
-
return [None, None, None, f'{result["password_strength"]}%', None]
|
86 |
-
|
87 |
-
def password_decrypt_callback(encrypted_password, key):
|
88 |
-
result = password_decrypt(encrypted_password, key)
|
89 |
-
return [None, None, None, None, result['password']]
|
90 |
-
|
91 |
-
interface.inputs[4].set_uploadable(False)
|
92 |
-
interface.inputs[5].set_uploadable(False)
|
93 |
-
interface.inputs[6].set_uploadable(False)
|
94 |
-
|
95 |
-
interface.inputs[4].set_action(generate_password_callback)
|
96 |
-
interface.inputs[5].set_action(password_strength_callback)
|
97 |
-
interface.inputs[6].set_action(password_decrypt_callback)
|
98 |
-
|
99 |
-
interface.launch()
|
|
|
1 |
+
import openai
|
2 |
+
import re
|
3 |
import gradio as gr
|
|
|
4 |
|
5 |
+
# Define a function to solve math problems
|
6 |
+
def solve_math_problem(prompt, api_key):
|
7 |
+
# Set up the OpenAI API credentials
|
8 |
+
openai.api_key = api_key
|
9 |
+
|
10 |
+
# Send the prompt to OpenAI's GPT-3 engine
|
11 |
+
response = openai.Completion.create(
|
12 |
+
engine="davinci",
|
13 |
+
prompt=prompt,
|
14 |
+
max_tokens=100,
|
15 |
+
n=1,
|
16 |
+
stop=None,
|
17 |
+
temperature=0.5,
|
18 |
+
)
|
19 |
+
|
20 |
+
# Extract the answer from the response
|
21 |
+
answer = response.choices[0].text.strip()
|
22 |
+
|
23 |
+
# Remove any non-numeric characters from the answer
|
24 |
+
answer = re.sub("[^0-9\.]", "", answer)
|
25 |
+
|
26 |
+
return float(answer)
|
27 |
+
|
28 |
+
# Define the Gradio interface
|
29 |
+
iface = gr.Interface(
|
30 |
+
fn=solve_math_problem,
|
31 |
+
inputs=[
|
32 |
+
gr.inputs.Textbox(label="Enter a math problem"),
|
33 |
+
gr.inputs.Textbox(label="Enter your OpenAI API key", type="password")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
],
|
35 |
+
outputs=gr.outputs.Textbox(label="Answer"),
|
36 |
+
title="OpenAI Calculator",
|
37 |
+
description="Enter a math problem and let OpenAI solve it for you!",
|
38 |
+
live=True
|
|
|
|
|
|
|
|
|
39 |
)
|
40 |
|
41 |
+
# Launch the Gradio interface
|
42 |
+
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|