Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import os
|
| 3 |
+
import sys
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from utils import process_dict, run_gpt_3, call3, call4, clean_and_concatenate_dict_values
|
| 6 |
+
|
| 7 |
+
def app(file):
|
| 8 |
+
try:
|
| 9 |
+
openai.api_key = os.environ['OPENAI_API_KEY']
|
| 10 |
+
except KeyError:
|
| 11 |
+
sys.stderr.write("""
|
| 12 |
+
You haven't set up your API key yet.
|
| 13 |
+
|
| 14 |
+
If you don't have an API key yet, visit:
|
| 15 |
+
|
| 16 |
+
You're a moron.
|
| 17 |
+
""")
|
| 18 |
+
exit(1)
|
| 19 |
+
with open(file.name, 'r') as f:
|
| 20 |
+
text = f.read()
|
| 21 |
+
batch_dict = process_dict(text, 20)
|
| 22 |
+
topic_dict = run_gpt_3(batch_dict, call3)
|
| 23 |
+
topic_text = clean_and_concatenate_dict_values(topic_dict)
|
| 24 |
+
result = call4(topic_text)
|
| 25 |
+
return result
|
| 26 |
+
|
| 27 |
+
iface = gr.Interface(fn=app, inputs="file", outputs="text")
|
| 28 |
+
iface.launch()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# response = openai.ChatCompletion.create(
|
| 36 |
+
# model="gpt-4", # only available if OpenAI has given you early access, otherwise use: "gpt-3.5-turbo"
|
| 37 |
+
# # 32K context gpt-4 model: "gpt-4-32k"
|
| 38 |
+
# messages=[
|
| 39 |
+
# {"role": "system", "content": "You are a helpful assistant."},
|
| 40 |
+
# {"role": "user", "content": "Who won the world series in 2020?"},
|
| 41 |
+
# {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
|
| 42 |
+
# {"role": "user", "content": "Where was it played?"}
|
| 43 |
+
# ]
|
| 44 |
+
# )
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
text = """
|
| 49 |
+
6.08 seconds - Yeah, the Jack Carr one was pretty fun.
|
| 50 |
+
11.32 seconds - He's super nice.
|
| 51 |
+
16.56 seconds - I'm really enjoying this book.
|
| 52 |
+
21.80 seconds - I can't wait to see what happens next.
|
| 53 |
+
27.04 seconds - This is a great read.
|
| 54 |
+
32.28 seconds - I highly recommend it to anyone who enjoys thrillers.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
print(process_dict(text))
|