File size: 1,338 Bytes
f1da378
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import tkinter as tk
import cohere

# Initialize the Cohere client
co = cohere.Client('mTeiGiDIpi4R7perkfRnMnCmi5jJzM8QziDVPrG8')  # Replace with your API key

# Create a function to generate text based on user input
def generate_text():
    prompt = input_box.get("1.0", "end-1c")  # Get the text from the input box
    response = co.generate(
        model='9b2e329d-7542-4c44-8f8c-cac03a6c4f5a-ft',
        prompt=prompt
    )
    output_text.config(state="normal")  # Allow editing of the output box
    output_text.delete("1.0", "end")  # Clear the previous output
    output_text.insert("1.0", response.generations[0].text)  # Display the new output
    output_text.config(state="disabled")  # Disable editing of the output box

# Create the main GUI window
root = tk.Tk()
root.title("Cohere Text Generation")

# Create an input box
input_label = tk.Label(root, text="Enter your prompt:")
input_label.pack()
input_box = tk.Text(root, height=5, width=40)
input_box.pack()

# Create a button to generate text
generate_button = tk.Button(root, text="Generate", command=generate_text)
generate_button.pack()

# Create an output box
output_label = tk.Label(root, text="Generated Text:")
output_label.pack()
output_text = tk.Text(root, height=10, width=40, state="disabled")
output_text.pack()

# Start the GUI event loop
root.mainloop()