Spaces:
Sleeping
Sleeping
File size: 1,604 Bytes
697911e 68678da 697911e |
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
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)) |