Friday, 17 January 2025

Hands on with Llama #2

Let us play with Gradio UI!

Creating a Gradio interface only requires adding a couple lines of code to your project. Seamlessly use any python library on your computer. If you can write a python function, gradio can run it.


GROQ_API_KEY = 'Your GROQ_API_KEY '
print('key:' , GROQ_API_KEY)

from langchain_groq import ChatGroq

chat = ChatGroq(
 
    api_key = GROQ_API_KEY,
    model_name = 'mixtral-8x7b-32768',
)

from langchain_core.prompts import ChatPromptTemplate

system = " You are an Expert"
human = "{text}"

prompt = ChatPromptTemplate.from_messages(
    [
        ("system", system), ("human", human)
    ]    
)

from langchain_core.output_parsers import StrOutputParser

chain = prompt| chat | StrOutputParser()

chain.invoke(
    {"text": "why the sky is blue?"}
)
# build an app
import gradio as gr
def fetch_response(user_input):
  chat = ChatGroq(
    api_key = GROQ_API_KEY,
    model_name = "mixtral-8x7b-32768"
  )
  system = "You are a helpful assistant."
  human = "{text}"

  prompt = ChatPromptTemplate.from_messages(
      [
          ("system", system), ("human", human)
      ]
  )
  chain = prompt | chat | StrOutputParser()
  output = chain.invoke({"text": user_input})
  return output
     
user_input = "why is the sky blue?"
fetch_response(user_input)

iface = gr.Interface(
    fn = fetch_response,
    inputs = "text",
    outputs = "text",
    title = "Groq Chatbot",
    description="Ask a question and get a response."
)
iface.launch(share= True)


output

Running on local URL:  http://127.0.0.1:7860

In user_input Text Area Type 

Write a python list with simple code snippet

and click submit, you will get response 


If you click flag button,
Everything will be save in dataset2.csv under flagged directory

user_input,output,timestamp
write a python list with simple code snippet,"Sure,
here is a simple Python code snippet that creates a list of numbers from 1 to 5:
```python
numbers = [1, 2, 3, 4, 5]
print(numbers)
```
When you run this code, it will output:
```csharp
[1, 2, 3, 4, 5]
```
You can also create a list of strings, for example:
```python
fruits = ['apple', 'banana', 'cherry', 'date']
print(fruits)
```
This will output:
```csharp
['apple', 'banana', 'cherry', 'date']
```
I hope this helps! Let me know if you have any other questions.",2025-01-18 00:33:36.397634

Got a simple magical Example, how to use GroQ and Gradio!


Hands on with Llama #2

Let us play with Gradio UI! Creating a Gradio interface only requires adding a couple lines of code to your project.  Seamlessly use any pyt...