ParseTimes / app.py
asuhag's picture
Upload app.py
36e6577 verified
import openai
import gradio as gr
from openai import OpenAI
import os
from datetime import datetime, date
import calendar
openai_api_key = os.getenv("OPENAI_API_KEY")
client = OpenAI(api_key=openai_api_key)
def predict(input, _):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "system",
"content": f"""Today's day, date and time is {calendar.day_name[date.today().weekday()], datetime.now()}. A text will be passed to you. Extract date and time from it. Output the date and time in the format YYYY-MM-DD hour:minutes.
If multiple date times are available, extract all dates and time from the text as a list data type and output them in the format YYYY-MM-DD hour:minutes.
Return an empty string if no date times are detected."""
},
{
"role": "user",
"content": input
}
],
temperature=0,
max_tokens=10,
top_p=1
)
return response.choices[0].message.content
#print(predict('Are you available for a meeting on 13th Feb at 2 pm '))
gr.ChatInterface(predict).launch()