File size: 840 Bytes
e5707d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import openai
from openai import OpenAI
import os

def query(prompt):
    client = client = OpenAI(api_key = os.getenv('OPENAPI_KEY')) # your own key

    system_prompt = """
      You are a helpful text sentiment classifier. Answer ONLY using these three options: ['Positive', 'Negative', 'Neutral']
    """

    user_prompt = f"""
      Classify the text into neutral, negative or positive.
      Text: {prompt}
      Sentiment:
    """

    message = [{"role": "system", "content": f"{system_prompt}"},{"role": "user", "content": f"{user_prompt}"}]

    response = client.chat.completions.create(
            model="gpt-3.5-turbo-1106",
            messages=message,
            temperature=0.5
    )
    return response.choices[0].message.content

gr.Interface(fn=query, inputs="textbox", outputs="textbox").launch()