Spaces:
Runtime error
Runtime error
Commit
·
8687413
1
Parent(s):
9063322
Update app.py
Browse files
app.py
CHANGED
@@ -1,45 +1,6 @@
|
|
1 |
import gradio as gr
|
2 |
-
import google.generativeai as genai
|
3 |
-
import upload_pdf
|
4 |
-
import re
|
5 |
-
import os
|
6 |
-
|
7 |
-
GOOGLE_API_KEY = os.getenv("GOOGLE_API_KEY")
|
8 |
-
|
9 |
-
# Now you can use hugging_face_api_key in your code
|
10 |
-
|
11 |
-
genai.configure(api_key=GOOGLE_API_KEY)
|
12 |
-
model = genai.GenerativeModel('gemini-pro') # Load the model
|
13 |
-
|
14 |
-
|
15 |
|
|
|
16 |
|
17 |
|
18 |
|
19 |
-
def get_Answer(query):
|
20 |
-
res = collection.query( # Assuming `collection` is defined elsewhere
|
21 |
-
query_texts=query,
|
22 |
-
n_results=2
|
23 |
-
)
|
24 |
-
system = f"""You are a teacher. You will be provided some context,
|
25 |
-
your task is to analyze the relevant context and answer the below question:
|
26 |
-
- {query}
|
27 |
-
"""
|
28 |
-
context = " ".join([re.sub(r'[^\x00-\x7F]+', ' ', r) for r in res['documents'][0]])
|
29 |
-
prompt = f"### System: {system} \n\n ###: User: {context} \n\n ### Assistant:\n"
|
30 |
-
answer = model.generate_content(prompt).text
|
31 |
-
return answer
|
32 |
-
|
33 |
-
# Define the Gradio interface
|
34 |
-
iface = gr.Interface(
|
35 |
-
fn=get_Answer,
|
36 |
-
inputs=gr.Textbox(lines=5, placeholder="Ask a question"), # Textbox for query
|
37 |
-
outputs="textbox", # Display the generated answer in a textbox
|
38 |
-
title="Answer Questions with Gemini-Pro",
|
39 |
-
description="Ask a question and get an answer based on context from a ChromaDB collection.",
|
40 |
-
)
|
41 |
-
|
42 |
-
# Launch the Gradio app
|
43 |
-
iface.launch(debug=True,share=True)
|
44 |
-
|
45 |
-
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
import upload_pdf
|
4 |
|
5 |
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|