I am trying to program this chatbot that generates poems using a text file. Here is the code:
import nltk
import openai
import gradio as gr
import gradio_client
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
nltk.download('punkt')
nltk.download('stopwords')
def load_file(ocean_poems):
with open(ocean_poems, 'r', encoding='utf-8') as file:
poems = file.readlines()
return poems`
poems = load_file("C:\Users\emily\Documents\ocean_poems.txt")
def pre_process(text):
tokens = word_tokenize(text)
tokens = [word.lower() for word in tokens if word.isalpha()]
tokens = [word for word in tokens if word not in stopwords.words('english')]
return ' '.join(tokens)
openai.api_key = "#####"
# My own API key would go here
def generate(prompt):
response = openai.ChatCompletion.create(
`model = "gpt-3.5-turbo",`
`prompt = prompt,`
`max_tokens = 5`
)
return response.choices[0].text.strip()
def generate_poem(prompt):
poem = generate(prompt)
return poem
gr.Interface
( fn=generate_poem,
inputs=gr.inputs.Textbox(),
outputs=gr.outputs.Textbox(),
title="Poem Generator"
).launch
The error I get from the chatbot inside VSCode says this:
I apologize for any confusion, but I am an AI language model and I cannot execute or run specific files on your computer. My capabilities are limited to generating text-based responses and engaging in cext-based responses and engaging in conversation. If you have any questions or need assistance with anything else, please let me know and I'll be happy to help!
How do I get this to run on the external link that should be created using Gradio?