CoolFace
Apppublic

frankio/goatheadrecs

sourceHugging Faceopenrailupdated 4y agoView on Hugging Face
0likes
app.py53 linesDownload Raw Back to root
1import openai2import gradio as gr3import requests4from bs4 import BeautifulSoup5 6openai.api_key = "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"7 8# Scrape artist names from website9url = "https://www.goatheadrecords.com/"10response = requests.get(url)11soup = BeautifulSoup(response.content, "html.parser")12artist_names = [artist.text.strip() for artist in soup.find_all("h2", class_="heading")]13artist_names += ["Sarah Azhari", "Beth Bella", "Morrison Machiavelli", "Y.Rome"]14 15messages = [16    {"role": "system", "content": "Hi there! I am an AI assistant from Goathead Records."},17]18 19def chatbot(input):20    if input:21        messages.append({"role": "user", "content": input})22        try:23            if "owner" in input.lower():24                reply = "The owner of Goathead Records is Frank Carrozzo. You can find more information about him on https://www.crunchbase.com/person/frank-carrozzo"25            elif "artists" in input.lower():26                reply = "The artists signed with Goathead Records are: " + ", ".join(artist_names)27            else:28                chat = openai.Completion.create(29                    engine="text-davinci-002",30                    prompt="\n".join([msg["content"] for msg in messages]),31                    max_tokens=1024,32                    n=1,33                    stop=None,34                    temperature=0.7,35                )36                reply = chat.choices[0].text37        except Exception as e:38            print(f"Error: {e}")39            reply = "Sorry, I'm having trouble processing your request. Please try again later."40        messages.append({"role": "assistant", "content": reply})41        return reply42 43inputs = gr.inputs.Textbox(lines=7, label="Chat with AI")44outputs = gr.outputs.Textbox(label="Reply")45 46gr.Interface(fn=chatbot, inputs=inputs, outputs=outputs, title="Goathead Records AI Chatbot",47             description="Ask me anything you want!",48             layout="vertical", font_family="Helvetica Neue", font_size="18px").launch(share=True)49 50 51 52 53