Spaces:
Sleeping
Sleeping
Update app.py
Browse files1234567891011121314151617181920import gradio as grimport sysprint("BOOT: app.py imported", flush=True)print("BOOT: Python version:", sys.version, flush=True)def hello():print("Button clicked", flush=True)return "App is running correctly."with gr.Blocks() as demo:gr.Markdown("# Minimal Test App")gr.Markdown("If you can see this, the app started successfully.")btn = gr.Button("Click me")output = gr.Textbox()btn.click(hello, outputs=output)if __name__ == "__main__":print("BOOT: Launching Gradio", flush=True)demo.launch(server_name="0.0.0.0", server_port=7860)1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859import gradio as grimport osimport yamlimport shutil# 确保 papers 文件夹存在os.makedirs("papers", exist_ok=True)def save_pdf(file):if file is None:return "Please upload a PDF file."# 获取文件名并保存到 papers 文件夹file_path = os.path.join("papers", os.path.basename(file.name))shutil.copy(file.name, file_path)return f"File saved successfully to {file_path}"def save_api_key(api_key):if not api_key:return "API Key cannot be empty."config_path = "config.yaml"try:# 读取现有的 yaml 文件with open(config_path, "r", encoding="utf-8") as f:config = yaml.safe_load(f) or {}# 确保 api_keys 字典存在,如果原文件中没有这个键,则初始化它if "api_keys" not in config:config["api_keys"] = {}# 更新嵌套的键config["api_keys"]["gemini_api_key"] = api_key# 将更新后的内容写回文件with open(config_path, "w", encoding="utf-8") as f:yaml.dump(config, f, allow_unicode=True, default_flow_style=False)return "Gemini API Key updated successfully in api_keys section!"except Exception as e:return f"Error saving API Key: {str(e)}"with gr.Blocks(title="PDF Uploader & Config") as demo:gr.Markdown("# PDF and API Configuration")with gr.Tab("Upload PDF"):file_input = gr.File(label="Upload your PDF", file_types=[".pdf"])upload_btn = gr.Button("Save PDF")upload_output = gr.Textbox(label="Status")upload_btn.click(save_pdf, inputs=file_input, outputs=upload_output)with gr.Tab("Gemini Configuration"):key_input = gr.Textbox(label="Enter Gemini API Key", type="password")key_btn = gr.Button("Save API Key")key_output = gr.Textbox(label="Status")key_btn.click(save_api_key, inputs=key_input, outputs=key_output)if __name__ == "__main__":demo.launch(server_name="0.0.0.0", server_port=7860)
app.py+52-13