Spaces:
Sleeping
Sleeping
import openai | |
import os | |
import sys | |
import gradio as gr | |
from utils import process_dict, run_gpt_3, call3, call4, clean_and_concatenate_dict_values | |
def app(file): | |
try: | |
openai.api_key = os.environ['OPENAI_API_KEY'] | |
except KeyError: | |
sys.stderr.write(""" | |
You haven't set up your API key yet. | |
If you don't have an API key yet, visit: | |
You're a moron. | |
""") | |
exit(1) | |
with open(file.name, 'r') as f: | |
text = f.read() | |
batch_dict = process_dict(text, 20) | |
topic_dict = run_gpt_3(batch_dict, call3) | |
topic_text = clean_and_concatenate_dict_values(topic_dict) | |
result = call4(topic_text) | |
return result | |
iface = gr.Interface(fn=app, inputs="file", outputs="text") | |
iface.launch() | |
# response = openai.ChatCompletion.create( | |
# model="gpt-4", # only available if OpenAI has given you early access, otherwise use: "gpt-3.5-turbo" | |
# # 32K context gpt-4 model: "gpt-4-32k" | |
# messages=[ | |
# {"role": "system", "content": "You are a helpful assistant."}, | |
# {"role": "user", "content": "Who won the world series in 2020?"}, | |
# {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."}, | |
# {"role": "user", "content": "Where was it played?"} | |
# ] | |
# ) | |
text = """ | |
6.08 seconds - Yeah, the Jack Carr one was pretty fun. | |
11.32 seconds - He's super nice. | |
16.56 seconds - I'm really enjoying this book. | |
21.80 seconds - I can't wait to see what happens next. | |
27.04 seconds - This is a great read. | |
32.28 seconds - I highly recommend it to anyone who enjoys thrillers. | |
""" | |
print(process_dict(text)) |