Spaces:
Sleeping
Sleeping
Commit
·
f1da378
1
Parent(s):
7628925
test.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tkinter as tk
|
2 |
+
import cohere
|
3 |
+
|
4 |
+
# Initialize the Cohere client
|
5 |
+
co = cohere.Client('mTeiGiDIpi4R7perkfRnMnCmi5jJzM8QziDVPrG8') # Replace with your API key
|
6 |
+
|
7 |
+
# Create a function to generate text based on user input
|
8 |
+
def generate_text():
|
9 |
+
prompt = input_box.get("1.0", "end-1c") # Get the text from the input box
|
10 |
+
response = co.generate(
|
11 |
+
model='9b2e329d-7542-4c44-8f8c-cac03a6c4f5a-ft',
|
12 |
+
prompt=prompt
|
13 |
+
)
|
14 |
+
output_text.config(state="normal") # Allow editing of the output box
|
15 |
+
output_text.delete("1.0", "end") # Clear the previous output
|
16 |
+
output_text.insert("1.0", response.generations[0].text) # Display the new output
|
17 |
+
output_text.config(state="disabled") # Disable editing of the output box
|
18 |
+
|
19 |
+
# Create the main GUI window
|
20 |
+
root = tk.Tk()
|
21 |
+
root.title("Cohere Text Generation")
|
22 |
+
|
23 |
+
# Create an input box
|
24 |
+
input_label = tk.Label(root, text="Enter your prompt:")
|
25 |
+
input_label.pack()
|
26 |
+
input_box = tk.Text(root, height=5, width=40)
|
27 |
+
input_box.pack()
|
28 |
+
|
29 |
+
# Create a button to generate text
|
30 |
+
generate_button = tk.Button(root, text="Generate", command=generate_text)
|
31 |
+
generate_button.pack()
|
32 |
+
|
33 |
+
# Create an output box
|
34 |
+
output_label = tk.Label(root, text="Generated Text:")
|
35 |
+
output_label.pack()
|
36 |
+
output_text = tk.Text(root, height=10, width=40, state="disabled")
|
37 |
+
output_text.pack()
|
38 |
+
|
39 |
+
# Start the GUI event loop
|
40 |
+
root.mainloop()
|