Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
openai.api_key = os.environ["OpenAPI_Key"]
|
| 6 |
+
|
| 7 |
+
def chunk_HTMLs(text, delimiter="HTML (ID:"):
|
| 8 |
+
""" This function splits the text into chunks based on a delimiter, removes trailing newlines from each chunk,
|
| 9 |
+
ignores any text before the first delimiter, and stores the chunks in a list. """
|
| 10 |
+
HTMLs = text.split(delimiter)
|
| 11 |
+
# Exclude the first chunk if it doesn't start with the delimiter
|
| 12 |
+
HTMLs = HTMLs[1:] if HTMLs[0] else HTMLs
|
| 13 |
+
# Remove trailing newlines, prepend the delimiter, and store the chunks in a list
|
| 14 |
+
return [delimiter + HTML.strip() for HTML in HTMLs]
|
| 15 |
+
|
| 16 |
+
def process_course(input_text):
|
| 17 |
+
""" Process the text input through Gradio and return the chunks. """
|
| 18 |
+
stored_HTMLs = chunk_HTMLs(input_text)
|
| 19 |
+
return '\n\n'.join(stored_HTMLs) # Join chunks for display
|
| 20 |
+
|
| 21 |
+
inputs = gr.Textbox(lines=7, label="Input Text")
|
| 22 |
+
outputs = gr.Textbox(label="Processed HTML Chunks")
|
| 23 |
+
|
| 24 |
+
# Create the Gradio interface with HTML-formatted output
|
| 25 |
+
iface = gr.Interface(
|
| 26 |
+
fn=chatbot,
|
| 27 |
+
inputs=inputs,
|
| 28 |
+
outputs=outputs,
|
| 29 |
+
title="Chunken van HTMLs",
|
| 30 |
+
description="Voer de tekst van een module in en druk op 'Submit'.",
|
| 31 |
+
theme="compact"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
iface.launch(share=False)
|