Spaces:
Build error
Build error
Upload folder using huggingface_hub
Browse files- README.md +3 -9
- gr_PDF_OpenAI.py +19 -0
README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
colorFrom: indigo
|
| 5 |
-
colorTo: gray
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
-
app_file: app.py
|
| 9 |
-
pinned: false
|
| 10 |
---
|
| 11 |
-
|
| 12 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: PDF_langchain_OpenAI_gr
|
| 3 |
+
app_file: gr_PDF_OpenAI.py
|
|
|
|
|
|
|
| 4 |
sdk: gradio
|
| 5 |
+
sdk_version: 3.50.0
|
|
|
|
|
|
|
| 6 |
---
|
|
|
|
|
|
gr_PDF_OpenAI.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain_openai import ChatOpenAI
|
| 2 |
+
from langchain.schema import AIMessage, HumanMessage
|
| 3 |
+
import os
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
|
| 7 |
+
|
| 8 |
+
llm = ChatOpenAI(temperature=1.0, model='gpt-3.5-turbo-0613')
|
| 9 |
+
|
| 10 |
+
def predict(message, history):
|
| 11 |
+
history_langchain_format = []
|
| 12 |
+
for human, ai in history:
|
| 13 |
+
history_langchain_format.append(HumanMessage(content=human))
|
| 14 |
+
history_langchain_format.append(AIMessage(content=ai))
|
| 15 |
+
history_langchain_format.append(HumanMessage(content=message))
|
| 16 |
+
gpt_response = llm(history_langchain_format)
|
| 17 |
+
return gpt_response.content
|
| 18 |
+
|
| 19 |
+
gr.ChatInterface(predict).launch(share=True)
|