coherebot / app.py
Tonic's picture
Update app.py
2e949bd
raw
history blame
842 Bytes
import cohere
# Initialize the Cohere client with your API key
api_key = os.getenv('COHERE_API_KEY')
if not api_key:
raise ValueError("Cohere API key not found in environment variables")
# Initialize the Cohere client with the API key from the environment variable
co = cohere.Client(api_key)
def generate_text(prompt):
# Generate a response using the Cohere model
response = co.generate(
model='746cb80b-3fba-43ec-b14f-1b0f84e9ed4d-ft',
prompt=prompt
)
# Return the generated text
return response.generations[0].text
# Create a Gradio interface
iface = gr.Interface(
fn=generate_text,
inputs="text",
outputs="text",
title="Cohere Chatbot",
description="Enter your prompt and get a response generated by Cohere.",
theme='ParityError/Anime'
)
# Launch the app
iface.launch()