Spaces:
Sleeping
Sleeping
Commit
·
e921c65
1
Parent(s):
335c99b
initial commit
Browse filesit is my first appli. i am bad in history but to help me for my homework.
- app.py +62 -0
- requirements.txt +0 -0
app.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import openai
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def openai_chat(api_key, system_prompt, user_prompt, temperature, max_tokens, top_p):
|
5 |
+
try:
|
6 |
+
# Set the OpenAI API key
|
7 |
+
openai.api_key = api_key
|
8 |
+
|
9 |
+
# Generate the completion
|
10 |
+
response = openai.ChatCompletion.create(
|
11 |
+
model="gpt-4",
|
12 |
+
messages=[
|
13 |
+
{"role": "system", "content": system_prompt},
|
14 |
+
{"role": "user", "content": user_prompt},
|
15 |
+
],
|
16 |
+
temperature=temperature,
|
17 |
+
max_tokens=max_tokens,
|
18 |
+
top_p=top_p,
|
19 |
+
)
|
20 |
+
|
21 |
+
# Extract the assistant's reply
|
22 |
+
return response['choices'][0]['message']['content']
|
23 |
+
|
24 |
+
except Exception as e:
|
25 |
+
return f"Error: {str(e)}"
|
26 |
+
|
27 |
+
# Define the Gradio interface
|
28 |
+
with gr.Blocks() as demo:
|
29 |
+
gr.Markdown("""# history prof
|
30 |
+
|
31 |
+
it is my first appli. i am bad in history but to help me for my homework.
|
32 |
+
""")
|
33 |
+
|
34 |
+
api_key_input = gr.Textbox(label="OpenAI API Key", placeholder="Enter your OpenAI API key", type="password")
|
35 |
+
system_prompt_input = gr.Textbox(label="ethan's history prof", value="You are a history professor 5e in FRENCH.", placeholder="You are a history professor 5e in FRENCH.")
|
36 |
+
user_prompt_input = gr.Textbox(label="user chat", placeholder="metez votre question ici.")
|
37 |
+
|
38 |
+
temperature_slider = gr.Slider(label="Temperature", minimum=0.0, maximum=1.0, value=0.7, step=0.1)
|
39 |
+
max_tokens_slider = gr.Slider(label="Max Tokens", minimum=10, maximum=1024, value=100, step=10)
|
40 |
+
top_p_slider = gr.Slider(label="Top P", minimum=0.1, maximum=1.0, value=1.0, step=0.1)
|
41 |
+
|
42 |
+
output = gr.Textbox(label="history prof 👨🏫 ")
|
43 |
+
|
44 |
+
generate_button = gr.Button("📖")
|
45 |
+
|
46 |
+
generate_button.click(
|
47 |
+
openai_chat,
|
48 |
+
inputs=[
|
49 |
+
api_key_input,
|
50 |
+
system_prompt_input,
|
51 |
+
user_prompt_input,
|
52 |
+
temperature_slider,
|
53 |
+
max_tokens_slider,
|
54 |
+
top_p_slider
|
55 |
+
],
|
56 |
+
outputs=[output]
|
57 |
+
)
|
58 |
+
|
59 |
+
if __name__ == "__main__":
|
60 |
+
demo.launch()
|
61 |
+
|
62 |
+
#Merci papa de m'avoir offert cet ordi ❤️❤️❤️
|
requirements.txt
ADDED
File without changes
|