File size: 1,074 Bytes
08bae0a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73c367e
2c4e183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess

# Define the pip command
pip_command = ["pip", "install", "gradio"]
pip_command = ["pip", "install", "langchain"]
pip_command = ["pip", "install", "google-generativeai"]
# Run the pip command using subprocess
try:
    # This will raise an error if the command fails
    subprocess.run(pip_command, check=True)
    subprocess.run(pip_command, check=True)
    subprocess.run(pip_command, check=True)
    print("done")
except subprocess.CalledProcessError as e:
    print("Failed to install gradio:", e)

import gradio as gr

from langchain.llms import GooglePalm
from langchain import PromptTemplate, LLMChain


llm = GooglePalm(temperature=0.1, google_api_key= "AIzaSyB5XIeNPyhIy29g4DUNZzVBKfsa-fVZtrk")

template = """Question: {question}

Answer: Let's think step by step."""

prompt_open = PromptTemplate(template=template, input_variables=["question"])

open_chain = LLMChain(prompt=prompt_open,llm = llm)


def predict(message, history):
    gpt_response = open_chain.run(message)
    return gpt_response

gr.ChatInterface(predict).launch(share=True)