Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from main import generate_text
|
| 3 |
+
|
| 4 |
+
def chat(state, message, file=None):
|
| 5 |
+
if file is not None:
|
| 6 |
+
# Handle file upload
|
| 7 |
+
response = generate_text(message, file)
|
| 8 |
+
else:
|
| 9 |
+
response = generate_text(message)
|
| 10 |
+
state = state + [(message, response)]
|
| 11 |
+
return state, state
|
| 12 |
+
|
| 13 |
+
with gr.ChatInterface(
|
| 14 |
+
chat=chat,
|
| 15 |
+
state=gr.State([]),
|
| 16 |
+
placeholder="Enter your prompt here...",
|
| 17 |
+
title="GPT-4 Chatbot",
|
| 18 |
+
theme="huggingface",
|
| 19 |
+
upload_file=True,
|
| 20 |
+
upload_file_output="upload",
|
| 21 |
+
) as chatbot:
|
| 22 |
+
chatbot.upload(
|
| 23 |
+
chat,
|
| 24 |
+
[chatbot.state, chatbot.input, chatbot.upload],
|
| 25 |
+
[chatbot, chatbot.state],
|
| 26 |
+
queue=False,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
chatbot.launch()
|