Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,31 @@
|
|
| 1 |
-
import
|
| 2 |
-
import
|
| 3 |
-
from langchain.llms import GenerativeModel
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
|
| 8 |
-
# Configure the model
|
| 9 |
-
llm = GenerativeModel("google-llm/text-davinci-003", api_key=API_KEY)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
Sends user input to Gemini and returns its response.
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
if user_input.lower() == "quit":
|
| 28 |
-
break
|
| 29 |
-
response = generate_response(user_input)
|
| 30 |
-
st.write( {response})
|
|
|
|
| 1 |
+
import gradio
|
| 2 |
+
from transformers import pipeline
|
|
|
|
| 3 |
|
| 4 |
+
# Initialize the Hugging Face model
|
| 5 |
+
model = pipeline(model='google/flan-t5-large')
|
| 6 |
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Define the chatbot function
|
| 9 |
+
def chatbot(input_text):
|
|
|
|
| 10 |
|
| 11 |
+
prompt = f"Give the answer of the given input in context from the bhagwat geeta. give suggestions to user which are based upon the meanings of shlok in bhagwat geeta, input = {input_text}"
|
| 12 |
+
# Generate a response from the Hugging Face model
|
| 13 |
+
response = model(prompt, max_length=250, do_sample=True)[0]['generated_text'].strip()
|
| 14 |
+
|
| 15 |
+
# Return the bot response
|
| 16 |
+
return response
|
| 17 |
|
| 18 |
+
# Define the Gradio interface
|
| 19 |
+
gradio_interface = gradio.Interface(
|
| 20 |
+
fn=chatbot,
|
| 21 |
+
inputs='text',
|
| 22 |
+
outputs='text',
|
| 23 |
+
title='Chatbot',
|
| 24 |
+
description='A weird chatbot conversations experience.',
|
| 25 |
+
examples=[
|
| 26 |
+
['Hi, how are you?']
|
| 27 |
+
]
|
| 28 |
+
)
|
| 29 |
|
| 30 |
+
# Launch the Gradio interface
|
| 31 |
+
gradio_interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|