Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cohere
|
2 |
+
|
3 |
+
# Initialize the Cohere client with your API key
|
4 |
+
api_key = os.getenv('COHERE_API_KEY')
|
5 |
+
if not api_key:
|
6 |
+
raise ValueError("Cohere API key not found in environment variables")
|
7 |
+
|
8 |
+
# Initialize the Cohere client with the API key from the environment variable
|
9 |
+
co = cohere.Client(api_key)
|
10 |
+
|
11 |
+
def generate_text(prompt):
|
12 |
+
# Generate a response using the Cohere model
|
13 |
+
response = co.generate(
|
14 |
+
model='746cb80b-3fba-43ec-b14f-1b0f84e9ed4d-ft',
|
15 |
+
prompt=prompt
|
16 |
+
)
|
17 |
+
# Return the generated text
|
18 |
+
return response.generations[0].text
|
19 |
+
|
20 |
+
# Create a Gradio interface
|
21 |
+
iface = gr.Interface(
|
22 |
+
fn=generate_text,
|
23 |
+
inputs="text",
|
24 |
+
outputs="text",
|
25 |
+
title="Cohere Chatbot",
|
26 |
+
description="Enter your prompt and get a response generated by Cohere."
|
27 |
+
theme='ParityError/Anime'
|
28 |
+
)
|
29 |
+
|
30 |
+
# Launch the app
|
31 |
+
iface.launch()
|