File size: 1,886 Bytes
8c5a3b3
 
 
 
 
 
 
94a4897
 
 
8c5a3b3
 
 
94a4897
 
8c5a3b3
94a4897
 
 
 
 
 
 
 
 
 
 
8c5a3b3
2ca96d7
 
 
 
249285c
 
94a4897
 
 
8c5a3b3
264f8d1
 
 
 
 
8c5a3b3
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
40
41
42
43
44
45
import os
import requests
import gradio as gr
from dotenv import load_dotenv

load_dotenv()

API_URL_FALCON = "https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct"
API_URL_GUANACO = "https://api-inference.huggingface.co/models/timdettmers/guanaco-33b-merged"
API_URL_PYTHIA = "https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5"

headers = {"Authorization": f"Bearer {os.getenv('HF_API_KEY')}"}

def query(api_url, payload):
    response = requests.post(api_url, headers=headers, json=payload)
    return response.json()

def respond(message):
    response_falcon = query(API_URL_FALCON, {"inputs": message})
    response_guanaco = query(API_URL_GUANACO, {"inputs": message})
    response_pythia = query(API_URL_PYTHIA, {"inputs": message})

    generated_text_falcon = response_falcon[0]['generated_text']
    generated_text_guanaco = response_guanaco[0]['generated_text']
    generated_text_pythia = response_pythia[0]['generated_text']

    return generated_text_falcon, generated_text_guanaco, generated_text_pythia

    

iface = gr.Interface(
    respond,
    inputs=gr.inputs.Textbox(label="Prompt for all the different models"),
    outputs=[
        gr.outputs.Textbox(label="Falcon Response"),
        gr.outputs.Textbox(label="Guanaco Response"),
        gr.outputs.Textbox(label="Pythia Response")
    ],
    title = "AI Response Aggregator with different LLM models in HugginFace. 🤗",
    description="The purpose is to show the interaction of different models so you can make rapid comparisons 🖥️💡",
    article="<p>This interface allows users to compare real-time outputs from multiple AI models, namely Falcon, Guanaco, and Pythia. By inputting a prompt, users can observe the different ways each model responds, providing a comprehensive view of their capabilities and styles.</p>"
)

iface.launch()