|
import gradio as gr |
|
import csv |
|
import os |
|
from datetime import datetime |
|
|
|
|
|
if not os.path.exists("reports.csv"): |
|
with open("reports.csv", "w", newline="") as f: |
|
writer = csv.writer(f) |
|
writer.writerow(["Message", "Reason", "Comment", "Date"]) |
|
|
|
def submit_report(message: str, reason: str, comment: str = "") -> str: |
|
with open("reports.csv", "a", newline="") as f: |
|
writer = csv.writer(f) |
|
writer.writerow([message, reason, comment, datetime.now()]) |
|
return "Report submitted successfully!" |
|
|
|
def view_reports() -> str: |
|
try: |
|
with open("reports.csv", "r") as f: |
|
return f.read() |
|
except: |
|
return "No reports found" |
|
|
|
|
|
with gr.Blocks() as demo: |
|
gr.Markdown("## Message Report System") |
|
|
|
with gr.Tab("Submit Report"): |
|
message = gr.Textbox(label="Message to Report") |
|
reason = gr.Radio(["Spam", "Offensive", "Other"], label="Reason") |
|
comment = gr.Textbox(label="Additional Comments (Optional)") |
|
submit = gr.Button("Submit Report") |
|
result = gr.Textbox(label="Status") |
|
|
|
submit.click(fn=submit_report, |
|
inputs=[message, reason, comment], |
|
outputs=result) |
|
|
|
with gr.Tab("View Reports"): |
|
view_btn = gr.Button("View All Reports") |
|
reports = gr.Textbox(label="Reports") |
|
|
|
view_btn.click(fn=view_reports, |
|
outputs=reports) |
|
|
|
demo.launch() |