|
975 | 975 | {
|
976 | 976 | "cell_type": "code",
|
977 | 977 | "execution_count": null,
|
978 |
| - "id": "38788603-90b8-40e1-9bee-6743a0175417", |
979 |
| - "metadata": { |
980 |
| - "scrolled": true |
981 |
| - }, |
| 978 | + "id": "ae437050", |
| 979 | + "metadata": {}, |
982 | 980 | "outputs": [],
|
983 | 981 | "source": [
|
984 |
| - "import gradio as gr\n", |
985 |
| - "\n", |
986 |
| - "\n", |
987 | 982 | "def generate_from_text(text_promt, input_image, neg_prompt, seed, num_steps, style_strength_ratio):\n",
|
988 | 983 | " \"\"\"\n",
|
989 | 984 | " Helper function for generating result image from prompt text\n",
|
|
1014 | 1009 | " width=1024,\n",
|
1015 | 1010 | " ).images[0]\n",
|
1016 | 1011 | "\n",
|
1017 |
| - " return result\n", |
1018 |
| - "\n", |
1019 |
| - "\n", |
1020 |
| - "with gr.Blocks() as demo:\n", |
1021 |
| - " with gr.Column():\n", |
1022 |
| - " with gr.Row():\n", |
1023 |
| - " input_image = gr.Image(label=\"Your image\", sources=[\"upload\"], type=\"pil\")\n", |
1024 |
| - " output_image = gr.Image(label=\"Generated Images\", type=\"pil\")\n", |
1025 |
| - " positive_input = gr.Textbox(label=f\"Text prompt, Trigger words is '{trigger_word}'\")\n", |
1026 |
| - " neg_input = gr.Textbox(label=\"Negative prompt\")\n", |
1027 |
| - " with gr.Row():\n", |
1028 |
| - " seed_input = gr.Slider(0, 10_000_000, value=42, label=\"Seed\")\n", |
1029 |
| - " steps_input = gr.Slider(label=\"Steps\", value=10, minimum=5, maximum=50, step=1)\n", |
1030 |
| - " style_strength_ratio_input = gr.Slider(label=\"Style strength ratio\", value=20, minimum=5, maximum=100, step=5)\n", |
1031 |
| - " btn = gr.Button()\n", |
1032 |
| - " btn.click(\n", |
1033 |
| - " generate_from_text,\n", |
1034 |
| - " [\n", |
1035 |
| - " positive_input,\n", |
1036 |
| - " input_image,\n", |
1037 |
| - " neg_input,\n", |
1038 |
| - " seed_input,\n", |
1039 |
| - " steps_input,\n", |
1040 |
| - " style_strength_ratio_input,\n", |
1041 |
| - " ],\n", |
1042 |
| - " output_image,\n", |
1043 |
| - " )\n", |
1044 |
| - " gr.Examples(\n", |
1045 |
| - " [\n", |
1046 |
| - " [prompt, negative_prompt],\n", |
1047 |
| - " [\n", |
1048 |
| - " \"A woman img wearing a Christmas hat\",\n", |
1049 |
| - " negative_prompt,\n", |
1050 |
| - " ],\n", |
1051 |
| - " [\n", |
1052 |
| - " \"A man img in a helmet and vest riding a motorcycle\",\n", |
1053 |
| - " negative_prompt,\n", |
1054 |
| - " ],\n", |
1055 |
| - " [\n", |
1056 |
| - " \"photo of a middle-aged man img sitting on a plush leather couch, and watching television show\",\n", |
1057 |
| - " negative_prompt,\n", |
1058 |
| - " ],\n", |
1059 |
| - " [\n", |
1060 |
| - " \"photo of a skilled doctor img in a pristine white lab coat enjoying a delicious meal in a sophisticated dining room\",\n", |
1061 |
| - " negative_prompt,\n", |
1062 |
| - " ],\n", |
1063 |
| - " [\n", |
1064 |
| - " \"photo of superman img flying through a vibrant sunset sky, with his cape billowing in the wind\",\n", |
1065 |
| - " negative_prompt,\n", |
1066 |
| - " ],\n", |
1067 |
| - " ],\n", |
1068 |
| - " [positive_input, neg_input],\n", |
1069 |
| - " )\n", |
| 1012 | + " return result" |
| 1013 | + ] |
| 1014 | + }, |
| 1015 | + { |
| 1016 | + "cell_type": "code", |
| 1017 | + "execution_count": null, |
| 1018 | + "id": "38788603-90b8-40e1-9bee-6743a0175417", |
| 1019 | + "metadata": { |
| 1020 | + "scrolled": true |
| 1021 | + }, |
| 1022 | + "outputs": [], |
| 1023 | + "source": [ |
| 1024 | + "if not Path(\"gradio_helper.py\").exists():\n", |
| 1025 | + " r = requests.get(url=\"https://raw.githubusercontent.com/openvinotoolkit/openvino_notebooks/latest/notebooks/photo-maker/gradio_helper.py\")\n", |
| 1026 | + " open(\"gradio_helper.py\", \"w\").write(r.text)\n", |
| 1027 | + "\n", |
| 1028 | + "from gradio_helper import make_demo\n", |
1070 | 1029 | "\n",
|
| 1030 | + "demo = make_demo(fn=generate_from_text)\n", |
1071 | 1031 | "\n",
|
1072 |
| - "demo.queue().launch()\n", |
| 1032 | + "try:\n", |
| 1033 | + " demo.queue().launch(debug=True)\n", |
| 1034 | + "except Exception:\n", |
| 1035 | + " demo.queue().launch(debug=True, share=True)\n", |
1073 | 1036 | "# if you are launching remotely, specify server_name and server_port\n",
|
1074 | 1037 | "# demo.launch(server_name='your server name', server_port='server port in int')\n",
|
1075 | 1038 | "# Read more in the docs: https://gradio.app/docs/"
|
|
1084 | 1047 | },
|
1085 | 1048 | "outputs": [],
|
1086 | 1049 | "source": [
|
1087 |
| - "demo.close()" |
| 1050 | + "# please uncomment and run this cell for stopping gradio interface\n", |
| 1051 | + "# demo.close()" |
1088 | 1052 | ]
|
1089 | 1053 | }
|
1090 | 1054 | ],
|
|
0 commit comments