sushantgo commited on
Commit
fde845c
1 Parent(s): 4a4e0a9

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. langchain-app.py +99 -0
langchain-app.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "Running on local URL: http://127.0.0.1:7863\n",
13
+ "Running on public URL: https://cf43e4871c9bab7308.gradio.live\n",
14
+ "\n",
15
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
16
+ ]
17
+ },
18
+ {
19
+ "data": {
20
+ "text/html": [
21
+ "<div><iframe src=\"https://cf43e4871c9bab7308.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
22
+ ],
23
+ "text/plain": [
24
+ "<IPython.core.display.HTML object>"
25
+ ]
26
+ },
27
+ "metadata": {},
28
+ "output_type": "display_data"
29
+ },
30
+ {
31
+ "data": {
32
+ "text/plain": []
33
+ },
34
+ "execution_count": 1,
35
+ "metadata": {},
36
+ "output_type": "execute_result"
37
+ }
38
+ ],
39
+ "source": [
40
+ "import os\n",
41
+ "import gradio as gr\n",
42
+ "from dotenv import load_dotenv, find_dotenv\n",
43
+ "_ = load_dotenv(find_dotenv())\n",
44
+ "\n",
45
+ "from langchain.chains import ConversationChain\n",
46
+ "from langchain.chat_models import ChatOpenAI\n",
47
+ "from langchain.memory import ConversationBufferMemory\n",
48
+ "\n",
49
+ "llm = ChatOpenAI(temperature=0.0)\n",
50
+ "memory = ConversationBufferMemory()\n",
51
+ "conversion = ConversationChain(\n",
52
+ " llm=llm,\n",
53
+ " memory=memory,\n",
54
+ " verbose=False\n",
55
+ ")\n",
56
+ "\n",
57
+ "def takeinput(name):\n",
58
+ " output_str = conversion.predict(input=name)\n",
59
+ " return output_str\n",
60
+ "\n",
61
+ "demo = gr.Interface(\n",
62
+ " fn=takeinput,\n",
63
+ " inputs=[\"text\"],\n",
64
+ " outputs=[\"text\"]\n",
65
+ ")\n",
66
+ "\n",
67
+ "demo.launch(share=True)\n"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "execution_count": null,
73
+ "metadata": {},
74
+ "outputs": [],
75
+ "source": []
76
+ }
77
+ ],
78
+ "metadata": {
79
+ "kernelspec": {
80
+ "display_name": "Python 3 (ipykernel)",
81
+ "language": "python",
82
+ "name": "python3"
83
+ },
84
+ "language_info": {
85
+ "codemirror_mode": {
86
+ "name": "ipython",
87
+ "version": 3
88
+ },
89
+ "file_extension": ".py",
90
+ "mimetype": "text/x-python",
91
+ "name": "python",
92
+ "nbconvert_exporter": "python",
93
+ "pygments_lexer": "ipython3",
94
+ "version": "3.11.4"
95
+ }
96
+ },
97
+ "nbformat": 4,
98
+ "nbformat_minor": 4
99
+ }