Spaces:
Sleeping
Sleeping
File size: 3,850 Bytes
4d17caa 8428312 2f264ab 4d17caa 2f264ab 4d17caa 2f264ab 4d17caa 2f264ab 4d17caa 2f264ab 4d17caa 74d5c72 4d17caa 2f264ab 4d17caa cf1cddb 4d17caa cf1cddb 4d17caa 74d5c72 4d17caa b8d2f65 4d17caa cf1cddb 4d17caa |
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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
import gradio as gr
from .pipeline import Pipeline
from .processing import process_file, process_text_input
def create_interface():
# Initialize the language model
language_model = Pipeline()
# Define the Output Format Selector
output_format_selector = gr.Radio(
choices=["CSV", "JSON"],
label="Select Output Format",
value="JSON",
type="value"
)
# Define the Output Flashcards
flashcard_output_file = gr.Textbox(
label="Flashcards",
lines=20,
placeholder="Your flashcards will appear here..."
)
flashcard_output_text = gr.Textbox(
label="Flashcards",
lines=20,
placeholder="Your flashcards will appear here..."
)
# Define the Gradio interface function for File Upload
def handle_file_upload(file_obj, output_format):
try:
flashcards = process_file(file_obj, output_format, Pipeline())
return flashcards
except ValueError as ve:
return str(ve)
# Define the Gradio interface function for Text Input
def handle_text_input(input_text, output_format):
try:
flashcards = process_text_input(input_text, output_format)
return flashcards
except ValueError as ve:
return str(ve)
# Create the Gradio Tabs
with gr.Blocks() as interface:
gr.Markdown("# Flashcard Studio")
gr.Markdown(
"Make flashcards from uploaded files or directly input text. Choose CSV or JSON output format."
)
with gr.Tab("Upload File"):
with gr.Row():
with gr.Column():
file_input = gr.File(
label="Upload a File",
file_types=['.txt', '.md']
)
format_selector = gr.Radio(
choices=["CSV", "JSON"],
label="Select Output Format",
value="CSV",
type="value"
)
submit_file = gr.Button("Extract Flashcards")
with gr.Column():
flashcard_output_file = gr.Textbox(
label="Flashcards",
lines=20,
placeholder="Extracted flashcards will appear here..."
)
submit_file.click(
fn=handle_file_upload,
inputs=[file_input, format_selector],
outputs=flashcard_output_file
)
with gr.Tab("Input Text"):
with gr.Row():
with gr.Column():
text_input = gr.Textbox(
label="Enter Text",
lines=20,
placeholder="Type or paste your text here..."
)
format_selector_text = gr.Radio(
choices=["CSV", "JSON"],
label="Select Output Format",
value="CSV",
type="value"
)
submit_text = gr.Button("Extract Flashcards")
with gr.Column():
flashcard_output_text = gr.Textbox(
label="Flashcards",
lines=20,
placeholder="Extracted flashcards will appear here..."
)
submit_text.click(
fn=handle_text_input,
inputs=[text_input, format_selector_text],
outputs=flashcard_output_text
)
gr.Markdown(
"""
---
**Notes:**
- Supported file types: `.txt`, `.md`.
"""
)
return interface
|