Spaces:
Sleeping
Sleeping
mrfirdauss
commited on
Commit
•
28b92d4
1
Parent(s):
bb51f59
Delete main.py
Browse files
main.py
DELETED
@@ -1,65 +0,0 @@
|
|
1 |
-
from pydantic import BaseModel
|
2 |
-
from fastapi import FastAPI
|
3 |
-
from transformers import AutoTokenizer, AutoModel
|
4 |
-
import torch
|
5 |
-
import faiss
|
6 |
-
import os
|
7 |
-
import requests
|
8 |
-
|
9 |
-
class Generate(BaseModel):
|
10 |
-
text:str
|
11 |
-
|
12 |
-
documents = ["Iben is a vibrant and passionate food influencer who has made a name for himself in the culinary world through his engaging content and exquisite taste. With a love for exploring diverse cuisines, Iben shares his culinary adventures on social media, captivating his audience with mouth-watering photos, detailed reviews, and innovative recipes. Known for his authenticity and connection with his followers, Iben has a knack for uncovering hidden gems in the food scene and presenting them in an appealing and relatable way. Whether he’s sampling street food or dining at high-end restaurants, Iben’s content is a delightful mix of gastronomic expertise and genuine enthusiasm for all things food.",
|
13 |
-
"""Dr. Tirta Mandira Hudhi, widely known as Dr. Tirta, is a prominent influencer and respected medical professional. Combining his expertise as a doctor with his entrepreneurial spirit, Dr. Tirta has built a unique brand that resonates with a wide audience. He holds a medical degree from Universitas Gadjah Mada and an M.B.A. from Institut Teknologi Bandung, demonstrating a strong foundation in both healthcare and business.
|
14 |
-
Dr. Tirta gained widespread recognition during the COVID-19 pandemic for his proactive efforts in public health education and advocacy. He utilized his platform to promote health protocols and telemedicine, earning trust and admiration from his followers. His ability to convey complex medical information in an engaging and accessible manner sets him apart as a reliable source of knowledge and inspiration.
|
15 |
-
Beyond his medical endeavors, Dr. Tirta is deeply entrenched in the fashion and sneaker industry, where he combines his love for street culture with business acumen. This diverse expertise allows him to connect with a broad demographic, making him an ideal influencer for brands looking to engage with health-conscious and trend-savvy consumers.
|
16 |
-
As a job market influencer, Dr. Tirta offers a compelling mix of professional credibility and relatable content. His dedication to improving public health, combined with his entrepreneurial mindset and cultural influence, makes him a valuable asset for any brand seeking to make a positive impact while reaching a diverse and engaged audience""",
|
17 |
-
"""Tasya Farasya is a renowned beauty influencer, entrepreneur, and content creator with a substantial following across multiple social media platforms. With a background in dentistry from Universitas Trisakti, Tasya transitioned her passion for makeup and beauty into a successful career, becoming one of Indonesia's most influential beauty figures.
|
18 |
-
Tasya is the founder and CEO of Mother of Pearl (MOP) Beauty, a cosmetic brand that reflects her commitment to high-quality and innovative beauty products. Her engaging content, which includes makeup tutorials, product reviews, and beauty tips, has garnered millions of followers on YouTube and Instagram. Her authenticity and expertise have earned her the trust and admiration of a diverse audience, from beauty enthusiasts to professional makeup artists.
|
19 |
-
Known for her creative approach and trendsetting style, Tasya has collaborated with numerous international and local beauty brands, significantly impacting purchasing decisions with her endorsements. Her ability to connect with her audience through relatable and informative content has solidified her position as a leading influencer in the beauty industry.
|
20 |
-
As a job market influencer, Tasya Farasya brings a wealth of experience, a broad audience reach, and a keen understanding of the beauty industry. Her dynamic presence and innovative mindset make her an invaluable partner for brands seeking to enhance their visibility and engage with a dedicated and enthusiastic community."""]
|
21 |
-
|
22 |
-
tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
|
23 |
-
model = AutoModel.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
|
24 |
-
API_KEY = os.getenv("API_KEY")
|
25 |
-
|
26 |
-
def embed_text(texts):
|
27 |
-
tokens = tokenizer(texts, return_tensors='pt', padding=True, truncation=True)
|
28 |
-
with torch.no_grad():
|
29 |
-
outputs = model(**tokens)
|
30 |
-
embeddings = outputs.last_hidden_state.mean(dim=1)
|
31 |
-
return embeddings
|
32 |
-
|
33 |
-
document_embeddings = embed_text(documents)
|
34 |
-
|
35 |
-
document_embeddings_np = document_embeddings.numpy()
|
36 |
-
index = faiss.IndexFlatL2(document_embeddings_np.shape[1])
|
37 |
-
index.add(document_embeddings_np)
|
38 |
-
|
39 |
-
app = FastAPI(title="Deploying FastAPI Apps on Huggingface")
|
40 |
-
|
41 |
-
@app.post("/generate", response_model=dict)
|
42 |
-
def generate_text(data: Generate):
|
43 |
-
global index, API_KEY
|
44 |
-
k = 1
|
45 |
-
D, I = index.search(embed_text(data.text).numpy(), k)
|
46 |
-
retrieved_docs = [documents[i] for i in I[0]]
|
47 |
-
# Combine retrieved documents
|
48 |
-
context = "\n\n".join(retrieved_docs)
|
49 |
-
|
50 |
-
prompt = f'### Context:\nHere is the list of influencer that you should included on your response\n{context}' + '\n\n ### Question:\nPlease use the provided context to answer the following question comprehensively. Supplement your response with relevant knowledge. Please provide your answer with engagement rate, proposed marketing strategy and estimated budget in number. Mention relevant influencer only. Answer the question using language that used user use. Evary currency must be provided in indonesian IDR. Your strategy should related with our influencer, maybe you can give like influencer campaign scheme. You have to mention the influencer name and contact on your response. Only mention influencer from our list.\n\n### Response:\n'+ data.text
|
51 |
-
|
52 |
-
url = f"https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key={API_KEY}"
|
53 |
-
headers = {
|
54 |
-
'Content-Type': 'application/json'
|
55 |
-
}
|
56 |
-
data = {
|
57 |
-
"contents": [{
|
58 |
-
"parts": [{
|
59 |
-
"text": prompt
|
60 |
-
}]
|
61 |
-
}]
|
62 |
-
}
|
63 |
-
|
64 |
-
response = requests.post(url, headers=headers, json=data)
|
65 |
-
return response.json()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|